creativefactoryrv/google-maps-geocoder
Composer 安装命令:
composer require creativefactoryrv/google-maps-geocoder
包简介
Simple and lightweight geocoder that uses the Google Maps Platform API. It can optionally use a PSR cache.
README 文档
README
A super simple geocoding class that use Google Maps Platform to do the magic.
You only need to obtain a Google Geocoding API key (https://developers.google.com/maps).
Optionally, the class can leverage a PRS-6 cache implementation in order to query the Maps Platform only when necessary.
Install
composer require creativefactoryrv/google-maps-geocoder
How to use
$geocoder = new Geocoder('XXXXXXXXX-My-Google-Geocoding-API-XXXXXXXXX', 'en'); $location = $geocoder->query('Duomo, Milano, Italy'); $latLng = $location->getCoordinates(); echo 'Lat: ' . $latLng['lat'] . ' / Lng: ' . $latLng['lng']; echo 'ZIP code: ' . $location->getPostalCode();
Get a JSON
Return the Google Maps Platform API response as it is (JSON).
$geocoder = new Geocoder('XXXXXXXXX-My-Google-Geocoding-API-XXXXXXXXX', 'en'); $location = $geocoder->query('Duomo, Milano, Italy'); $myJSONString = $location->getRaw();
Get an array
Return the Google Maps Platform API response as an associative array.
$geocoder = new Geocoder('XXXXXXXXX-My-Google-Geocoding-API-XXXXXXXXX', 'en'); $location = $geocoder->query('Duomo, Milano, Italy'); $myArray = $location->toArray();
Get latitude and longitude
Returns an array with the desired values.
$geocoder = new Geocoder('XXXXXXXXX-My-Google-Geocoding-API-XXXXXXXXX', 'en'); $location = $geocoder->query('Duomo, Milano, Italy'); $myArray = $location->getCoordinates();
Country
Returns the country value.
$geocoder = new Geocoder('XXXXXXXXX-My-Google-Geocoding-API-XXXXXXXXX', 'en'); $location = $geocoder->query('Duomo, Milano, Italy'); echo $location->getCountry();
Locality (city)
Returns the city or locality value.
$geocoder = new Geocoder('XXXXXXXXX-My-Google-Geocoding-API-XXXXXXXXX', 'en'); $location = $geocoder->query('Duomo, Milano, Italy'); echo $location->getLocality();
Postal code
Returns the postal code or zipcode value.
$geocoder = new Geocoder('XXXXXXXXX-My-Google-Geocoding-API-XXXXXXXXX', 'en'); $location = $geocoder->query('Duomo, Milano, Italy'); echo $location->getPostalCode();
Route (street name)
Returns the street name (called "route" by Google).
$geocoder = new Geocoder('XXXXXXXXX-My-Google-Geocoding-API-XXXXXXXXX', 'en'); $location = $geocoder->query('Duomo, Milano, Italy'); echo $location->getRoute();
Street number
Returns the street number value.
$geocoder = new Geocoder('XXXXXXXXX-My-Google-Geocoding-API-XXXXXXXXX', 'en'); $location = $geocoder->query('Duomo, Milano, Italy'); echo $location->getStreetNumber();
Administrative levels 1
Returns the administrative levels 1 value.
$geocoder = new Geocoder('XXXXXXXXX-My-Google-Geocoding-API-XXXXXXXXX', 'en'); $location = $geocoder->query('Duomo, Milano, Italy'); echo $location->getAdministrativeAreaLevel1();
Administrative levels 2
Returns the administrative levels 2 value.
$geocoder = new Geocoder('XXXXXXXXX-My-Google-Geocoding-API-XXXXXXXXX', 'en'); $location = $geocoder->query('Duomo, Milano, Italy'); echo $location->getAdministrativeAreaLevel2();
Administrative levels 3
Returns the administrative levels 3 value.
$geocoder = new Geocoder('XXXXXXXXX-My-Google-Geocoding-API-XXXXXXXXX', 'en'); $location = $geocoder->query('Duomo, Milano, Italy'); echo $location->getAdministrativeAreaLevel3();
Formatted address
Returns a string representing the address (called "formatted_address" by Google).
$geocoder = new Geocoder('XXXXXXXXX-My-Google-Geocoding-API-XXXXXXXXX', 'en'); $location = $geocoder->query('Duomo, Milano, Italy'); echo $location->getFormattedAddress();
Format as you like
Returns a formatted address according to $format.
- %A1 Administrative Area Level 1
- %a1 Administrative Area Level 1 (short version)
- %A2 Administrative Area Level 2
- %a2 Administrative Area Level 2 (short version)
- %A3 Administrative Area Level 3
- %a3 Administrative Area Level 3 (short version)
- %C Country
- %L Locality
- %P Postal code
- %R Route
- %N Street number
$geocoder = new Geocoder('XXXXXXXXX-My-Google-Geocoding-API-XXXXXXXXX', 'en'); $location = $geocoder->query('Duomo, Milano, Italy'); $format = '%R %N, %C'; echo $location->format($format);
License
MIT
creativefactoryrv/google-maps-geocoder 适用场景与选型建议
creativefactoryrv/google-maps-geocoder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 35 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 09 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「geocoding」 「geocoder」 「cache」 「caching」 「google maps」 「Google Maps Platform」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 creativefactoryrv/google-maps-geocoder 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 creativefactoryrv/google-maps-geocoder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 creativefactoryrv/google-maps-geocoder 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Maps in minutes. Powered by the Google Maps API.
repository php library
Yii2 map input widget. Allows you to select geographcal coordinates via a human-friendly inteface.
GISCO Geocoding Provider for Geocoder PHP.
Integration of Geocoder into Symfony2
Laravel integration for Nominatim Geocoding API Client
统计信息
- 总下载量: 35
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-09-28