php-geocoder

In almost all projects, we need or we use some kind of geospatial data, either that may be latitude, longitude, zip codes, address, city etc. Which can be later used to show or plot on google maps or bing maps or any such websites. So to convert lat,lng to zip or lat,lng to city or lat,lng to any particular address or vice versa, we need geocoders, using which we can either perform geocoding or reverse geocoding.

There is a powerful library available in PHP, called Geocoder-PHP, using which we can easily perform such geocoding related tasks. This library supports lot of third-party services like google maps, geonames, TomTom, Bing Maps etc. Geocoder-PHP also supports IP-to-geo feature. As mentioned a very powerfull library, which supports a wide range of geo related services.

Installing geocoder:

Geocoder-php can be install using composer.
Following code will do that for you:

composer-geocoder-php

Once it will be installed successfully, we will following folders:

php-geocoder

We will be using google maps api for this example. Lets create a file, say, geocode.php, we will see an example of geocoding:

Example-1 geocoding:

geocoder-php-geocode

Example-2 reverse geocoding:

geocoder-php-reverse-geocode

Note: please consider number of requests, limits each service provider follow.

All the service providers have some limitations on number of requesrs you can do daily or monthly. Have a look on those

GitHub Link: http://geocoder-php.org/Geocoder/

— Create your Geocoder or Reverse geocoder in PHP —