rotron/php-geocode

一个围绕 Google 地理编码 API 的包装器,用于获取有关特定地址的详细信息,如纬度、经度、国家、城市、地区、邮编、镇和街道号码。

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

This package is not auto-updated.

Last update: 2024-09-20 20:31:31 UTC


README

Add inside config/app.php
'Geocode'   => Rotron\Geocode\Geocode::class

Call from controller with Post or Get request.
 public function location(Request $request)
 {
        $geocode = new Geocode();
        $street = $request->input('street');
        // Get the details for the passed address
        $location = $geocode->get($street);     
        $location = $location->streetAddress;
     
        return view('store.location', compact('location'));
} 

PHP 地理编码

Latest Stable Version

一个围绕 Google 地理编码 API 的包装器,用于获取关于地址的以下详细信息:

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

需求

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

安装

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

Composer

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

{
    "require": {
        "rotron/php-geocode": "dev-master"
    }
}

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

入门

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

1600 Amphitheatre Parkway, Mountain View, CA

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

// Introduce the class into your scope
use Rotron\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

反馈

我很想听听您的意见。请为任何您可能想要的特性请求或您注意到的错误打开一个问题。您也可以通过 kamranahmed.se@gmail.com 或在推特 @kamranahmed_se 找到我。

注意

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

  • 每 24 小时 2,500 个请求。
  • 每秒 5 个请求。