kamranahmedse/php-geocode

该软件包已被废弃且不再维护。作者建议使用 hugobots/php-geocode 软件包。

此软件包是 Google 地理编码 API 的包装器,用于获取有关特定地址的不同详细信息,例如纬度、经度、国家、城市、地区、邮编、镇和街道号码。

v2.0 2016-01-22 19:59 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:40:11 UTC


README

不再维护,更好的替代方案是 geocoder-php

PHP Geocode

Build Status Scrutinizer Code Quality

Google 地理编码 API 的包装器,用于获取有关地址的不同详细信息,例如

  • 纬度/经度
  • 国家
  • 城市
  • 地区
  • 邮编
  • 街道号码

要求

PHP >= 5.4.0 和已启用 curl 的服务器。

安装

您可以使用以下方式安装库

Composer

推荐的安装方法是使用 Composer,一个 PHP 依赖管理器。只需将 hugobots/php-geocode 添加到您的项目 composer.json 文件中

{
    "require": {
        "hugobots/php-geocode": "*"
    }
}

然后运行 composer install。有关更多详细信息,您可以在 Packagist 中找到该软件包。

手动方式

或者,您可以手动安装软件包

  • src/php-geocode.php 复制到您的代码库中,可能到 vendor 目录。
  • Geocode 类添加到您的自动加载器中或直接要求该文件。

入门

我将使用以下地址来解释库的使用,即

1600 Amphitheatre Parkway, Mountain View, CA

实例化 Geocode 类并按如下方式调用方法

// Introduce the class into your scope
use KamranAhmed\Geocode\Geocode;


// Optionally you can pass the API key for Geocoding
$geocode = new Geocode();

// Get the details for the passed address
$location = $geocode->get("1600 Amphitheatre Parkway, Mountain View, CA");

// Note: All the functions below accept a parameter as a default value that will be return if the reuqired value isn't found
$location->getAddress( 'default value' ); 
$location->getLatitude(); // returns the latitude of the address
$location->getLongitude(); // returns the longitude of the address
$location->getCountry(); // returns the country of the address
$location->getLocality(); // returns the locality/city of the address
$location->getDistrict(); // returns the district of the address
$location->getPostcode(); // returns the postal code of the address
$location->getTown(); // returns the town of the address
$location->getStreetNumber(); // returns the street number of the address
$location->getNeighborhood(); // returns the neighborhood of the address

反馈

我很乐意听到您的意见。请为任何您可能希望请求的功能或您发现的错误打开一个问题。您还可以通过 kamranahmed.se@gmail.com 或您也可以在推特上找到我 @kamranahmedse

注意

请注意,Google 地理编码 API 已实施以下限制,您在使用此包装器之前应牢记这些限制

  • 每天 2,500 次请求。
  • 每秒 5 次请求。