francoisvaillant/geolocator
Composer 安装命令:
composer require francoisvaillant/geolocator
包简介
Geolocator is a simple tool to geolocate address or reverse. It is also able to determinate altitude.
README 文档
README
Geolocator is a simple tool to geolocate address or reverse. It is also capable to determinate altitude.
It uses 3 Api :
- https://adresse.data.gouv.fr/api-doc/adresse
- https://nominatim.org/release-docs/develop/
- https://www.opentopodata.org/
Setup
composer require francoisvaillant/geolocator
namespaces
- \Francoisvaillant\Geolocator\
- \Francoisvaillant\Geolocator\Providers
All begin by a place
$place = new Place()
By default, we uses french Government "adresses Api". If you prefer (especially out of France), you can use NominatimApi by setting it as provider for your Place :
$place = new Place(NominatimProvider::class)
Get Coordinates from address
In order to geolocate an address, your have first to set it and setting City or ZipCode. City is often not enough. It's highly recommended to set city and zipCode before using geolocation.
$place ->setAddress('your address'); ->setCity('city name'); ->setZipCode(00000); ->geolocate(); $latitude = $place->getLatitude(); // NULL if geolocation failed $longitude = $place->getLongitude(); // NULL if geolocation failed
Get address from coordinates
$place ->setLatitude(45.548); ->setLongitude(1.897); ->reverse(); $address = $place->getAddress(); // NULL if reverse failed $zipCode = $place->getZipCode(); // NULL if reverse failed $city = $place->getCity(); // NULL if reverse failed
Get altitude from coordinates
uses OpenTopoData APi. See https://www.opentopodata.org/ for details and restrictions
$place ->setLatitude(45.548); ->setLongitude(1.897); ->findAltitude() ->getAltitude(); // NULL if failed
If you host your own instance of OpenTopoData Api, please change AltitudeProvider :
$altitudeProvider = new AltitudeProvider('http://localhost:5000/v1/srtm30m?locations=%s,%s'); // note that first %s is for latitude, second one is for longitude $place->setAltitudeProvider($altitudeProvider);
What you can get :
Once you totally hydrated your Place whith ->geolocate() or ->reverse() (altitude is a bit different), you'll be able to get all the above informations (However depends on the provider) :
- city
- zipCode
- address
- inseeCode
- department code
- departement name
- region name
- latitude and longitude (degrees)
- latitude and longitude (lambert93)
Note that the geolocate() and reverse() return true or false if succeed or not. So you can use :
if($place->geolocate()) { // ... } if($place->reverse()) { // ... }
If you want to check all the response from Api after geolocate(), reverse() or findAltitude() :
$place //... ->geolocate(); $place->getProvider()->getResponseData(); $place //... ->reverse(); $place->getProvider()->getResponseData(); $place //... ->findAltitude(); $place->getAltitudeProvider()->getResponseData();
francoisvaillant/geolocator 适用场景与选型建议
francoisvaillant/geolocator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 27 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 01 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 francoisvaillant/geolocator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 francoisvaillant/geolocator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 27
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-01-16