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:


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


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:


Example-2 reverse geocoding:


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:

— Create your Geocoder or Reverse geocoder in PHP —