80

So I have latitude and longitude Like 44.4647452 and 7.3553838. I need to get address like: Milan, Italy, str. Kennedy 89.

How I can do it?

L84
  • 45,514
  • 58
  • 177
  • 257
Boris Kuzevanov
  • 1,232
  • 1
  • 12
  • 21

3 Answers3

177

Simply pass latitude, longitude and your Google API Key to the following query string, you will get a json array, fetch your city from there.

https://maps.googleapis.com/maps/api/geocode/json?latlng=44.4647452,7.3553838&key=YOUR_API_KEY

Note: Ensure that no space exists between the latitude and longitude values when passed in the latlng parameter.

Click here to get an API key

user2092317
  • 3,226
  • 5
  • 24
  • 35
  • 7
    sensor = false :P or you can just omit that parameter entirely now – user3308043 Aug 03 '14 at 03:08
  • 2
    @user3308043 Do we need to register our application for above google api call? – Umang Kothari Feb 04 '16 at 06:21
  • @UmangKothari No, you don't need to register an app for this api call only !!! – Kirankumar Dafda Jun 27 '16 at 07:04
  • @Kirankumar, And number of calls are limited?? Btw thank you! – Umang Kothari Jun 27 '16 at 07:24
  • 1
    No @UmangKothari, there is no limit of calls too :) – Kirankumar Dafda Jun 27 '16 at 09:46
  • @KirankumarDafda -- I am using the above URL in PHP and usually it works very well - however sometimes returns null data? Have you ever seen that issue and any suggestions? It is very intermittent but does happen. The latlng is valid and previously returned a valid address but on a second call, or third call, or nth call for same latng will return a null for address? Any thoughts on why? I rarely use this URL more than a few times a day. – Neal Davis Feb 28 '18 at 22:39
  • @NealDavis try adding url with your lat long into browser's address bar and refresh page until you get the error message other than your required output and try resolving that error will work for you. – Kirankumar Dafda Mar 01 '18 at 09:41
  • not valid anymore : "error_message": "You must use an API key to authenticate each request to Google Maps Platform APIs. – Dawit Jan 19 '19 at 10:12
  • Davvit: I have updated the answer. – user2092317 Jan 22 '19 at 15:50
  • How I can get the first address from ResponseBody? Like .getFirstAddress()? – Cipri Feb 15 '23 at 19:31
17

What your looking for is Reverse Geo Coding. Have a look at this example here. https://developers.google.com/maps/documentation/javascript/examples/geocoding-reverse

Sajuna Fernando
  • 1,364
  • 9
  • 16
9

You have to make one ajax call to get the required result, in this case you can use Google API to get the same

http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true/false

Build this kind of url and replace the lat long with the one you want to. do the call and response will be in JSON, parse the JSON and you will get the complete address up to street level

Amir Koklan
  • 897
  • 2
  • 12
  • 32
Dinesh Prajapati
  • 9,274
  • 5
  • 30
  • 47