phpfacile/geocoding 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

phpfacile/geocoding

Composer 安装命令:

composer require phpfacile/geocoding

包简介

Service mainly aimed at retrieving coordinates (latitude, longitude) of a location (address, place).

README 文档

README

This is mainly aimed at retrieving coordinates (latitude, longitude) of a location (address, place).

It is based on geocoder-php (https://github.com/geocoder-php/Geocoder) and tries to use the provider matching our requirements:

  • The provider must allow geocoding output storage
  • The provider usage must be free (for few queries)

REM: A cache is used so as to meet as far as possible usage limitation defined by the providers

Installation

At the root of your project type

composer require phpfacile/geocoding

Or add "phpfacile/geocoding": "^1.0" to the "require" part of your composer.json file

"require": {
    "phpfacile/geocoding": "^1.0"
}

Providers comparison

Providers Storage allowed? Restrictions
Geonames Yes No more than 1 req/s
GoogleMap for 30 days max
MapBox No
Nominatim Yes No more than 1 req/s

Usage

$geocodingService = new GeocodingService($cfg, $cacheDir);

$cfg = [
    'geonames' => [
        'username' => '<replace with geonames username>',
    ],
    'nominatim' => [
        'rootUrl' => 'https://nominatim.openstreetmap.org',
        'userAgent' => '<replace with a user-agent>',
    ]
];

$cacheDir.'/nominatim' must exist (ex: if $cacheDir='/cache' then '/cache/nominatim' folder must exist and be writable)

Actually, in the current implementation, in any case nominatim is the preferred provider.

$locations = $this->geocodingService->getLocationsByAddress('Etretat, France');
foreach ($locations as $location) {
    var_dump($location);
}

$locations = $this->geocodingService->getPlacesByCountryAndPlaceName('France', 'Etretat');
foreach ($locations as $location) {
    var_dump($location);
}

Disclaimer

Nominatim may stop its service at any moment

Troubleshooting

If ever you modify the code so as to use geonames, you have to know that the following error message is silently ignored by the geonames provider (https://github.com/geocoder-php/geonames-provider)

{"status":{"message":"user account not enabled to use the free webservice. Please enable it on your account page: http://www.geonames.org/manageaccount ","value":10}}

Todo

  • Manage localisation
  • Remove unexpected (from a human point of view) results (for example, with nominatim, a query for "Paris, France" currently returns an entry with type="city" and an other entry almost identical but with type="administrative")

统计信息

  • 总下载量: 23
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-11-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固