Calling/Using Google Maps API reverse geocoder from PHP

Still talking about web GIS here..

Reverse geocoder is a way of converting GPS coordinate (latitude, longitude) into human readable address.

Instead of JavaScript, we also can call reverse geocoder feature from Google Maps API via PHP. This is useful if you are somehow need to get user position in human readable format not only as latitude and longitude pair. You can then save this return value to database or just looking for a place name that has address similar to the returned value (addresses).

This is working example code in PHP:

Example result:

As you can see, Google Maps give you several level of human readable address. You may interested in “formatted_address” of results object. It is the human readable address that you can show directly to user. A way of calling it (example):

Other interesting object is address_components, you can, for example, get visitor’s state/province by looping of types array under each address_components object.

  1. Raju Kumar Jaiswal

    I tried your code above by saving it as .php file…But i am getting an error as

    ( ! ) Notice: Trying to get property of non-object in C:\wamp\www\index.php on line 10
    Call Stack
    # Time Memory Function Location
    1 0.0008 368112 {main}( ) ..\index.php:0

    ( ! ) Notice: Trying to get property of non-object in C:\wamp\www\index.php on line 15
    Call Stack
    # Time Memory Function Location
    1 0.0008 368112 {main}( ) ..\index.php:0

  2. Hello! I see the post now, I ask, if you can really save the return data in a database, that in the conditions of Google says that is not permitted, perhaps in some cases if possible?

Leave a Reply

%d bloggers like this: