PHPackages                             nekulin/geocoder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. nekulin/geocoder

ActiveLibrary

nekulin/geocoder
================

The almost missing Geocoder PHP 5.4 library.

v3.3.0(10y ago)024MITPHPPHP &gt;=5.4.0

Since Jan 2Pushed 10y ago1 watchersCompare

[ Source](https://github.com/nekulin/Geocoder)[ Packagist](https://packagist.org/packages/nekulin/geocoder)[ Docs](http://geocoder-php.org)[ RSS](/packages/nekulin-geocoder/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (4)Versions (57)Used By (0)

Geocoder
========

[](#geocoder)

[![Build Status](https://camo.githubusercontent.com/1971e06f55456caecadf5fb297aa7f7ac695ae7eca77bb3f4fb4899feb1dcb93/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f67656f636f6465722d7068702f47656f636f6465722e706e67)](http://travis-ci.org/geocoder-php/Geocoder)[![Total Downloads](https://camo.githubusercontent.com/b60888b2b6574d273cdf2b3176647575f0481863c6491b7c5f93edfd29a15669/68747470733a2f2f706f7365722e707567782e6f72672f77696c6c647572616e642f47656f636f6465722f646f776e6c6f6164732e706e67)](https://packagist.org/packages/willdurand/Geocoder)[![Latest Stable Version](https://camo.githubusercontent.com/dd46cd65c818797ec89330352c0bd52f597f49226b69d56fcfcd836643b01f1d/68747470733a2f2f706f7365722e707567782e6f72672f77696c6c647572616e642f47656f636f6465722f762f737461626c652e706e67)](https://packagist.org/packages/willdurand/Geocoder)[![PHP7 ready](https://camo.githubusercontent.com/1bdeb491d2b30d89ec425c42b74dba8d14431e7355c551cb5a573b46f4e0bf35/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f504850372d72656164792d677265656e2e737667)](https://camo.githubusercontent.com/1bdeb491d2b30d89ec425c42b74dba8d14431e7355c551cb5a573b46f4e0bf35/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f504850372d72656164792d677265656e2e737667)

> **Important:** You are browsing the documentation of Geocoder **3.x**. Documentation for version **2.x** is available here: [Geocoder 2.x documentation](https://github.com/geocoder-php/Geocoder/blob/2.x/README.md).

---

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

- [Installation](#installation)
- [Usage](#usage)
    - [Address &amp; AddressCollection](#address--addresscollection)
    - [The ProviderAggregator](#the-provideraggregator)
    - [TimedGeocoder](#timedgeocoder)
    - [HTTP Adapters](#http-adapters)
    - [Providers](#providers)
        - [Address-based Providers](#address-based-providers)
            - [ArcGISOnline](#arcgisonline)
            - [GeoIP2](#geoip2)
            - [GoogleMaps](#googlemaps)
            - [GoogleMapsBusiness](#googlemapsbusiness)
            - [MaxMindBinary](#maxmindbinary)
            - [Nominatim](#nominatim)
            - [TomTom](#tomtom)
            - [Yandex](#yandex)
        - [IP-based Providers](#ip-based-providers)
        - [Locale Aware Providers](#locale-aware-providers)
        - [The Chain Provider](#the-chain-provider)
    - [Dumpers](#dumpers)
        - [GPS eXchange Format (GPX)](#gps-exchange-format-gpx)
        - [GeoJSON](#geojson)
        - [Keyhole Markup Language (KML)](#keyhole-markup-language-kml)
        - [Well-Known Binary (WKB)](#well-known-binary-wkb)
        - [Well-Known Text (WKT)](#well-known-text-wkt)
    - [Formatters](#formatters)
- [Extending Things](#extending-things)
- [Versioning](#versioning)

Installation
------------

[](#installation)

The recommended way to install Geocoder is through [Composer](http://getcomposer.org):

```
$ composer require willdurand/geocoder

```

Usage
-----

[](#usage)

[Geocoder](https://github.com/geocoder-php/Geocoder) and its companion [Geocoder Extra](https://github.com/geocoder-php/geocoder-extra) provides a lot of [providers](#providers).

Choose the one that fits your need first. Let's say the `GoogleMaps` one is what you were looking for, so let's see how to use it. In the code snippet below, `curl` has been chosen as [HTTP layer](#http-adapters) but it is up to you since each HTTP-based provider implements [PSR-7](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md).

```
$curl     = new \Ivory\HttpAdapter\CurlHttpAdapter();
$geocoder = new \Geocoder\Provider\GoogleMaps($curl);

$geocoder->geocode(...);
$geocoder->reverse(...);
```

The `Geocoder` interface, which all providers implement, exposes two main methods:

- `geocode($streetOrIpAddress)`
- `reverse($latitude, $longitude)`

It also contains methods to control the number of results:

- `limit($limit)`
- `getLimit()`

### Address &amp; AddressCollection

[](#address--addresscollection)

Both `geocode()` and `reverse()` methods return a collection of `Address`objects (`AddressCollection`), each providing the following API:

- `getCoordinates()` will return a `Coordinates` object (with `latitude` and `longitude` properties);
- `getLatitude()` will return the `latitude` value;
- `getLongitude()` will return the `longitude` value;
- `getBounds()` will return an `Bounds` object (with `south`, `west`, `north`and `east` properties);
- `getStreetNumber()` will return the `street number/house number` value;
- `getStreetName()` will return the `street name` value;
- `getLocality()` will return the `locality` or `city`;
- `getPostalCode()` will return the `postalCode` or `zipcode`;
- `getSubLocality()` will return the `city district`, or `sublocality`;
- `getAdminLevels()` will return an ordered collection (`AdminLevelCollection`) of `AdminLevel` object (with `level`, `name` and `code` properties);
- `getCountry()` will return a `Country` object (with `name` and `code`properties);
- `getCountryCode()` will return the ISO `country` code;
- `getTimezone()` will return the `timezone`.

The `AddressCollection` exposes the following methods:

- `count()` (this class implements `Countable`);
- `first()` retrieves the first `Address`;
- `slice($offset, $length = null)` returns `Address` objects between `$offset`and `length`;
- `get($index)` fetches an `Address` using its `$index`;
- `all()` returns all `Address` objects;
- `getIterator()` (this class implements `IteratorAggregate`).

### The ProviderAggregator

[](#the-provideraggregator)

The `ProviderAggregator` is used to register several providers so that you can decide which provider to use later on.

```
