Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

The most featured Geocoder library written in PHP.

License

NotificationsYou must be signed in to change notification settings

rubythonode/Geocoder

 
 

Build StatusSoftware License

Important: You are browsing the documentation of Geocoder4.x.

Documentation for version3.x is available here:Geocoder 3.xdocumentation.

Documentation for version2.x is available here:Geocoder 2.xdocumentation.


Geocoder is a PHP library which helps you build geo-aware applications byproviding a powerful abstraction layer for geocoding manipulations.

Installation

To install a Geocoder there are two things you need to know:

  1. WhatGeocoder provider you want to use
  2. WhatHTTP client/adapter you want to use.

Geocoder providers

Since 4.0 we do not include providers by default. You need to select ageocoder provider. You will see a list ofprovidersat Packagist

HTTP Clients

In order to talk to geocoding APIs, you need HTTP adapters. While it was part ofthe library in Geocoder before, Geocoder 4.x and upper now relies on HTTPlugwhich defines how HTTP message should be sent and received. You can use any library to send HTTP messagesthat implementsphp-http/client-implementation.

Here is a list of all officially supported clients and adapters by HTTPlug:http://docs.php-http.org/en/latest/clients.html

Read more about HTTPlug intheir docs.

Summary (Just give me the command)

To install Google Maps geocoder with Guzzle 6 you may run the following command:

$ composer require geocoder-php/google-maps-provider php-http/guzzle6-adapter

Or using the curl client (you'll need to provide a PSR7 implementation such asnyholm/psr7 if not using guzzle)

$ composer require geocoder-php/google-maps-provider php-http/curl-client nyholm/psr7

Framework integration

If you are using a framework then you may be interested in our excellent framework integrations.

FrameworkPackageStats
Laravelgeocoder-php/GeocoderLaravelGitHub releasePackagist
Symfonygeocoder-php/BazingaGeocoderBundleLatest Stable VersionTotal Downloads

Cookbook

We have a small cookbook where you can find examples on common use cases:

Usage

In the code snippet below we use GoogleMaps and Guzzle6.

useGeocoder\Query\GeocodeQuery;useGeocoder\Query\ReverseQuery;$httpClient =new \Http\Adapter\Guzzle6\Client();$provider =new \Geocoder\Provider\GoogleMaps\GoogleMaps($httpClient,null,'your-api-key');$geocoder =new \Geocoder\StatefulGeocoder($provider,'en');$result =$geocoder->geocodeQuery(GeocodeQuery::create('Buckingham Palace, London'));$result =$geocoder->reverseQuery(ReverseQuery::fromCoordinates(...));

TheProvider interface has three methods:

  • geocodeQuery(GeocodeQuery $query):AddressCollection
  • reverseQuery(ReverseQuery $query):AddressCollection
  • getName():string

TheGeocoder interface extends theProvider interface and exposes two additional methods. They willmake migration from 3.x smoother.

  • geocode($streetOrIpAddress)
  • reverse($latitude, $longitude)

Providers

Providers perform the geocoding black magic for you (talking to the APIs, fetching results, dealing with errors, etc.)and are highly configurable.

Special providers

ProviderPackageFeaturesStats
Cachegeocoder-php/cache-providerWraps a provider and cached the resultsLatest Stable Version
Total Downloads
Chaingeocoder-php/chain-providerIterates over multiple providersLatest Stable Version
Total Downloads

Address

World

ProviderPackageFeaturesStats
Algolia Placesgeocoder-php/algolia-places-provideraddress
Website
Latest Stable Version
Total Downloads
ArcGIS Onlinegeocoder-php/arcgis-online-provideraddress, reverse
Website
Latest Stable Version
Total Downloads
Bing Mapsgeocoder-php/bing-maps-provideraddress, reverse
Website
Latest Stable Version
Total Downloads
Geocode Earthgeocoder-php/geocode-earth-provideraddress, reverse
Website
Latest Stable Version
Total Downloads
Geonamesgeocoder-php/geonames-provideraddress, reverse
Website
Latest Stable Version
Total Downloads
Google Maps
Google Maps for business
geocoder-php/google-maps-provideraddress, reverse
Website
Latest Stable Version
Total Downloads
Google Maps Placesgeocoder-php/google-maps-places-provideraddress, reverse
Website
Latest Stable Version
Total Downloads
GraphHoppergeocoder-php/graphhopper-provideraddress, reverse
Website
Latest Stable Version
Total Downloads
Heregeocoder-php/here-provideraddress, reverse
Website
Latest Stable Version
Total Downloads
LocationIQgeocoder-php/locationiq-provideraddress, reverse
Website
Latest Stable Version
Total Downloads
Mapboxgeocoder-php/mapbox-provideraddress, reverse
Website
Latest Stable Version
Total Downloads
MapQuestgeocoder-php/mapquest-provideraddress, reverse
Website
Latest Stable Version
Total Downloads
Nominatim
(OpenStreetMap)
geocoder-php/nominatim-provideraddress, reverse
Website
Latest Stable Version
Total Downloads
OpenCagegeocoder-php/open-cage-provideraddress, reverse
Website
Latest Stable Version
Total Downloads
OpenRouteServicegeocoder-php/openrouteservice-provideraddress, reverse
Website
Latest Stable Version
Total Downloads
Peliasgeocoder-php/pelias-provideraddress, reverse
Website
Latest Stable Version
Total Downloads
Photongeocoder-php/photon-provideraddress, reverse
Website
Latest Stable Version
Total Downloads
PickPointgeocoder-php/pickpoint-provideraddress, reverse
Website
Latest Stable Version
Total Downloads
TomTomgeocoder-php/tomtom-provideraddress, reverse
Website
Latest Stable Version
Total Downloads
Yandexgeocoder-php/yandex-provideraddress, reverse
Website
Latest Stable Version
Total Downloads

Local

RegionProviderPackageFeaturesStats
🇧🇪bpost (third-party package*)geo6/geocoder-php-bpost-provideraddress
Website
Latest Stable Version
Total Downloads
🇧🇪GeoPunt (third-party package*)geo6/geocoder-php-geopunt-provideraddress, reverse
Website
Latest Stable Version
Total Downloads
🇧🇪Service Public de Wallonie (third-party package*)geo6/geocoder-php-spw-provideraddress, reverse
Website
Latest Stable Version
Total Downloads
🇧🇪UrbIS (third-party package*)geo6/geocoder-php-urbis-provideraddress, reverse
Website
Latest Stable Version
Total Downloads
🇫🇷Addok (third-party package*)geo6/geocoder-php-addok-provideraddress, reverse
Website
Latest Stable Version
Total Downloads
🇱🇺Geoportail.lu (third-party package*)frantzmicccoli/geocoder-php-geoportail-luaddress, reverse
Website
Latest Stable Version
Total Downloads
🇳🇱Nationaal Georegister (third-party package*)swisnl/geocoder-php-nationaal-georegister-provideraddress, reverse
Website
Latest Stable Version
Total Downloads

*Third-party package: Those providers are not official, i.e. not from the Geocoder core team.

IP

ProviderPackageFeaturesStats
FreeGeoIpgeocoder-php/free-geoip-providerIPv4, IPv6
Website
Latest Stable Version
Total Downloads
GeoIPgeocoder-php/geoip-providerIPv4, local
Website
Latest Stable Version
Total Downloads
GeoIP2geocoder-php/geoip2-providerIPv4
Website
Latest Stable Version
Total Downloads
GeoPlugingeocoder-php/geo-plugin-providerIPv4, IPv6
Website
Latest Stable Version
Total Downloads
HostIpgeocoder-php/host-ip-providerIPv4
Website
Latest Stable Version
Total Downloads
IP2Locationgeocoder-php/ip2location-providerIPv4, IPv6
Website
Latest Stable Version
Total Downloads
IP2Location Binarygeocoder-php/ip2location-binary-providerIPv4, IPv6
Website
Latest Stable Version
Total Downloads
IpInfogeocoder-php/ip-info-providerIPv4, IPv6
Website
Latest Stable Version
Total Downloads
IpInfoDBgeocoder-php/ip-info-db-providerIPv4
Website
Latest Stable Version
Total Downloads
ipstackgeocoder-php/ipstack-providerIPv4, IPv6
Website
Latest Stable Version
Total Downloads
MaxMindgeocoder-php/maxmind-providerIPv4, IPv6
Website
Latest Stable Version
Total Downloads
MaxMind Binarygeocoder-php/maxmind-binary-providerIPv4, IPv6
Website
Latest Stable Version
Total Downloads

Other packages

There are two "abstract" or "base" packages that most providers depend on.

NamePackageFeaturesStats
PHP commonwilldurand/geocoderModels, interfaces, exceptions etcLatest Stable Version
Total Downloads
HTTP commongeocoder-php/common-httpAbstractHttpProvider, HTTPlugLatest Stable Version
Total Downloads
Plugingeocoder-php/pluginPlugin providerLatest Stable Version
Total Downloads

Special Geocoders and Providers

The Chain Provider

TheChain provider is a special provider that takes a list of providers anditerates over this list to get information. Note that itstops its iterationwhen a provider returns a result. The result is returned byGoogleMaps becauseFreeGeoIp andHostIp cannot geocode street addresses.BingMaps is ignored.

useGeocoder\Query\GeocodeQuery;$geocoder =new \Geocoder\ProviderAggregator();$adapter  =new \Http\Adapter\Guzzle6\Client();$chain =new \Geocoder\Provider\Chain\Chain([new \Geocoder\Provider\FreeGeoIp\FreeGeoIp($adapter),new \Geocoder\Provider\HostIp\HostIp($adapter),new \Geocoder\Provider\GoogleMaps\GoogleMaps($adapter,'France'),new \Geocoder\Provider\BingMaps\BingMaps($adapter,'<API_KEY>'),// ...]);$geocoder->registerProvider($chain);$result =$geocoder->geocodeQuery(GeocodeQuery::create('10 rue Gambetta, Paris, France'));var_export($result);

Everything is ok, enjoy!

The ProviderAggregator

TheProviderAggregator is used to register several providers so that you candecide which provider to use later on.

useGeocoder\Query\GeocodeQuery;useGeocoder\Query\ReverseQuery;$adapter  =new \Http\Adapter\Guzzle6\Client();$geocoder =new \Geocoder\ProviderAggregator();$geocoder->registerProviders([new \Geocoder\Provider\GoogleMaps\GoogleMaps($adapter),new \Geocoder\Provider\GoogleMaps\GoogleMapsBusiness($adapter,'<CLIENT_ID>'),new \Geocoder\Provider\Yandex\Yandex($adapter),new \Geocoder\Provider\MaxMind\MaxMind($adapter,'<MAXMIND_API_KEY>'),new \Geocoder\Provider\ArcGISOnline\ArcGISOnline($adapter),]);$geocoder->registerProvider(new \Geocoder\Provider\Nominatim\Nominatim($adapter,'https://your.nominatim.server'));$geocoder    ->using('google_maps')    ->geocodeQuery(GeocodeQuery::create( ... ));$geocoder    ->limit(10)    ->reverseQuery(ReverseQuery::fromCoordinates($lat,$lng));

TheProviderAggregator's API is fluent, meaning you can write:

useGeocoder\Query\GeocodeQuery;$locations =$geocoder    ->registerProvider(new \My\Provider\Custom($adapter))    ->using('custom')    ->limit(10)    ->geocodeQuery(GeocodeQuery::create( ... ));

Theusing() method allows you to choose theprovider to use by its name.When you deal with multiple providers, you may want to choose one of them. Thedefault behavior is to use the first one but it can be annoying.

Thelimit() method allows you to configure the maximum number of results beingreturned. Depending on the provider you may not get as many results as expected,it is a maximum limit, not the expected number of results.

TimedGeocoder

TheTimedGeocoder class profiles eachgeocode andreverse call. So you caneasily figure out how many time/memory was spent for each geocoder/reverse call.

useGeocoder\Query\GeocodeQuery;// configure your provider$provider =// ...$stopwatch =new \Symfony\Component\Stopwatch\Stopwatch();$geocoder =new \Geocoder\TimedGeocoder($provider,$stopwatch);$geocoder->geocodeQuery(GeocodeQuery::create('Paris, France'));// Now you can debug your application

We use thesymfony/stopwatchcomponent under the hood. Which means, if you use the Symfony framework thegeocoder calls will appear in your timeline section in the Web Profiler.

StatefulGeocoder

TheStatefulGeocoder class is great when you want your Geocoder to hold state. Say you want to configure locale,limit or bounds in runtime. TheStatefulGeocoder will append these values on each query.

useGeocoder\Query\GeocodeQuery;// configure your provider$provider =// ...$geocoder =new \Geocoder\StatefulGeocoder($provider);$geocoder->setLocale('en');$results =$geocoder->geocodeQuery(GeocodeQuery::create('London'));echo$results->first()->getLocality();// London$geocoder->setLocale('es');$results =$geocoder->geocodeQuery(GeocodeQuery::create('London'));echo$results->first()->getLocality();// Londres

Dumpers

Geocoder provides dumpers that aim to transform aLocation object instandard formats.

GPS eXchange Format (GPX)

TheGPS eXchange format is designed to share geolocated data like point ofinterests, tracks, ways, but also coordinates.Geocoder provides a dumper toconvert aLocation object in an GPX compliant format.

Assuming we got a$location object as seen previously:

$dumper =new \Geocoder\Dumper\Gpx();$strGpx =$dumper->dump($location);echo$strGpx;

It will display:

<gpxversion="1.0"creator="Geocoder"version="1.0.1-dev"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://www.topografix.com/GPX/1/0"xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">    <boundsminlat="2.388911"minlon="48.863151"maxlat="2.388911"maxlon="48.863151"/>    <wptlat="48.8631507"lon="2.3889114">        <name><![CDATA[Paris]]></name>        <type><![CDATA[Address]]></type>    </wpt></gpx>

GeoJSON

GeoJSON is a format for encoding a variety of geographicdata structures.

GeoArray

Simple PHP array format for using with your own encoders.

Keyhole Markup Language (KML)

Keyhole Markup Languageis an XML notation for expressing geographic annotation and visualization withinInternet-based, two-dimensional maps and three-dimensional Earth browsers.

Well-Known Binary (WKB)

The Well-Known Binary (WKB) representation for geometric values is defined bythe OpenGIS specification.

Well-Known Text (WKT)

Well-known text (WKT) is a text markup language for representing vector geometryobjects on a map, spatial reference systems of spatial objects andtransformations between spatial reference systems.

Formatters

A common use case is to print geocoded data. Thanks to theStringFormatterclass, it's simple to format aLocation object as a string:

// $location is an instance of Location$formatter =new \Geocoder\Formatter\StringFormatter();$formatter->format($location,'%S %n, %z %L');// 'Badenerstrasse 120, 8001 Zuerich'$formatter->format($location,'<p>%S %n, %z %L</p>');// '<p>Badenerstrasse 120, 8001 Zuerich</p>'

Here is the mapping:

  • Street Number:%n
  • Street Name:%S
  • City (Locality):%L
  • City District (Sub-Locality):%D
  • Zipcode (Postal Code):%z
  • Admin Level Name:%A1,%A2,%A3,%A4,%A5
  • Admin Level Code:%a1,%a2,%a3,%a4,%a5
  • Country:%C
  • Country Code:%c
  • Timezone:%T

Versioning

Geocoder followsSemantic Versioning.

End Of Life

1.x

As of December 2014, branch1.7 is not officially supported anymore, meaningmajor version1 reached end of life. Last version is:1.7.1.

2.x

As of December 2014, version2.xis in afeature frozen state. All new features should be contributed to version 3.0and upper. Last version is:2.8.1.

Major version2 will reachend of life on December 2015.

3.x

As of January 2017, version3.xis in afeature frozen state. All new features should be contributed to version 4.0and upper. Last version is:3.3.2.

Major version3 will reachend of life on October 2017.

Stable Version

Version4.x is the current major stable version of Geocoder.

Next version

There is no new major version planned at this time.

Contributing

SeeCONTRIBUTING file.

Unit Tests

In order to run the test suite, install the development dependencies:

$ composer install --dev

Then, run the following command:

$ composer test

You'll obtain someskipped unit tests due to the need of API keys.

Rename thephpunit.xml.dist file tophpunit.xml, then uncomment thefollowing lines and add your own API keys:

<php><!-- <server name="IPINFODB_API_KEY" value="YOUR_API_KEY" />--><!-- <server name="BINGMAPS_API_KEY" value="YOUR_API_KEY" />--><!-- <server name="GEOIPS_API_KEY" value="YOUR_API_KEY" />--><!-- <server name="MAXMIND_API_KEY" value="YOUR_API_KEY" />--><!-- <server name="GEONAMES_USERNAME" value="YOUR_USERNAME" />--><!-- <server name="TOMTOM_MAP_KEY" value="YOUR_MAP_KEY" />--><!-- <server name="GOOGLE_GEOCODING_KEY" value="YOUR_GEOCODING_KEY" />--><!-- <server name="OPENCAGE_API_KEY" value="YOUR_API_KEY" />--><!-- <server name="PICKPOINT_API_KEY" value="YOUR_API_KEY" />--><!-- <server name="LOCATIONIQ_API_KEY" value="YOUR_API_KEY" />--><!-- <server name="IPSTACK_API_KEY" value="YOUR_API_KEY" />--></php>

You're done.

Credits

License

Geocoder is released under the MIT License. See the bundled LICENSE file for details.

About

The most featured Geocoder library written in PHP.

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP100.0%

[8]ページ先頭

©2009-2025 Movatter.jp