adamb/google-maps-geocoder

PHP 对 Google Maps 地理编码 API v3 的包装。

v4.2.3 2017-07-13 14:10 UTC

This package is auto-updated.

Last update: 2024-09-15 02:58:28 UTC


README

Latest Stable Version Total Downloads

PHP 对 Google Maps 地理编码 API v3 的包装。

Justin StaytonMonk Development 期间开发。

要求

  • PHP >= 5.2.0

安装

Composer

推荐安装方式是通过 Composer,PHP 的依赖管理器。只需将 adamb/google-maps-geocoder 添加到您的项目 composer.json 文件中

{
    "require": {
        "adamb/google-maps-geocoder": "*"
    }
}

更多详情可在 Packagist 上找到。

手动

  1. src/GoogleMapsGeocoder.php 复制到您的代码库中,例如到 vendor 目录。
  2. GoogleMapsGeocoder 类添加到您的自动加载器或直接 require 文件。

入门

我们将使用 Monk Development 的地址作为示例

$address = "2707 Congress St., San Diego, CA 92110";

设置 GoogleMapsGeocoder 对象地址有两种方式。地址可以是构造函数中传递的

$Geocoder = new GoogleMapsGeocoder($address);

或者创建对象后设置地址

$Geocoder = new GoogleMapsGeocoder();
$Geocoder->setAddress($address);

默认情况下,format 设置为 jsonsensor 设置为 false。这些值可以通过构造函数或创建对象后进行更改。有关可以更改的完整 API 参数列表,请参阅 文档

设置完所有参数后,最后一步是向 Google Maps 地理编码 API 发送请求

$response = $Geocoder->geocode();

geocode 方法将响应转换为 JSON 关联数组(默认)或根据指定的 format 转换为 SimpleXMLElement 对象。有关通过 HTTPS 进行请求或防止转换(返回原始纯文本响应)的说明,请参阅 geocode文档

贡献

  1. 分支它。
  2. 创建您的功能分支(git checkout -b my-new-feature)。
  3. 提交您的更改(git commit -am 'Added some feature')。
  4. 将分支推送到远程(git push origin my-new-feature)。
  5. 创建一个新的拉取请求。