mustafakucuk/google-places 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mustafakucuk/google-places

Composer 安装命令:

composer require mustafakucuk/google-places

包简介

A simple PHP wrapper for the new Google Places API, making it easy to perform place searches, retrieve details, and use autocomplete features.

README 文档

README

This PHP wrapper provides an easy-to-use interface for interacting with the Google Places API. It simplifies the process of making API requests for place searches, place details, and autocomplete features. The wrapper handles API authentication, request formatting, and response parsing, allowing developers to integrate Google Places functionality into their PHP applications with minimal effort.

Features

  • Nearby Search: Search for places near a specified location within a given radius.
  • Place Details: Retrieve detailed information about a specific place using its place ID.
  • Text Search: Search for places based on a text query.
  • Autocomplete: Get place suggestions based on partial user input.

Installation

To use this wrapper, you'll need to have Composer installed.

composer require mustafakucuk/google-places

Usage

Initialization

Before you can make any requests, you need to initialize the client with your Google Places API key:

use GooglePlaces\Client;

$client = new Client('your_api_key_here');

Nearby Search

Search for places near a specified location within a given radius:

$location = '37.7749,-122.4194'; // Latitude, Longitude
$radius = 500; // Radius in meters
$params = [
    'includedTypes' => ['restaurant'],
    'fields' => ['places.id', 'places.displayName'],
];

$places = $client->near_by_search($location, $radius, $params);
print_r($places);

Place Details

Retrieve detailed information about a specific place using its place ID:

$place_id = 'ChIJlYL0Wa-BhYARJi6qr49Ncv1';
$fields = ['displayName', 'id', 'googleMapsUri', 'formattedAddress'];

$place_details = $client->get_place($place_id, $fields);
print_r($place_details);

Text Search

Search for places based on a text query:

$query = 'restaurants in Sydney';
$fields = ['places.id', 'places.displayName'];

$places = $client->search_text($query, $fields);
print_r($places);

Autocomplete

Get place suggestions based on partial user input:

$input = 'Pizza';
$params = [
    'includedPrimaryTypes' => ['mexican_restaurant'],
];
$suggestions = $client->autocomplete($input, $params);
print_r($suggestions);

Methods

prepare_fields(array|string $fields, bool $clean_prefix = false): string

Formats and prepares the fields parameter for API requests.

  • $fields: The fields to be included in the API request. Can be provided as an array or a comma-separated string. Defaults to '*' if empty.
  • $clean_prefix: Optional. If true, removes the places. prefix from field names. Defaults to false.
  • Returns: A formatted, comma-separated string of fields.

near_by_search(string $location, int $radius, array $params = []): array

Performs a nearby search for places.

  • $location: A comma-separated string representing the latitude and longitude (e.g., "37.7749,-122.4194").
  • $radius: The radius (in meters) within which to search for places.
  • $params: Optional. Additional parameters for the API request.
  • Returns: An associative array of places.

get_place(string $place_id, array $fields = []): array

Retrieves details about a specific place using its place ID.

  • $place_id: The unique identifier of the place.
  • $fields: Optional. An array of fields to include in the response.
  • Returns: An associative array with place details.

search_text(string $query, array $fields = []): array

Performs a text-based search for places.

  • $query: The search query text.
  • $fields: Optional. An array of fields to include in the response.
  • Returns: An associative array of places.

autocomplete(string $input, array $params = []): array

Provides autocomplete suggestions based on user input.

  • $input: The partial text input from the user.
  • $params: Optional. Additional parameters for the API request.
  • Returns: An array of autocomplete suggestions.

Error Handling

The wrapper throws exceptions when it encounters errors. Ensure you handle exceptions in your implementation:

try {
    $places = $client->near_by_search($location, $radius, $params);
} catch (\Exception $e) {
    // Handle errors
}

mustafakucuk/google-places 适用场景与选型建议

mustafakucuk/google-places 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 47 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 09 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 mustafakucuk/google-places 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mustafakucuk/google-places 我们能提供哪些服务?
定制开发 / 二次开发

基于 mustafakucuk/google-places 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 47
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-02