3

I need to convert a lat/long coordinates to a address. I could use the Google Maps API but I would need a XML Response. I have looked at Convert Lat Long to address Google Maps ApiV2 but I need to be able to do this in JavaScript.
My Question is: How To Convert a Lat/Long coordinate to an address?

Community
  • 1
  • 1
user2574350
  • 1,383
  • 3
  • 10
  • 7

3 Answers3

2

You can use GeoNames' FindNearestAddress.

It takes a latitude and longitude parameter and returns the nearest address in XML format.

From the example:

http://api.geonames.org/findNearestAddress?lat=37.451&lng=-122.18&username=demo

<address>
 <street>Roble Ave</street>
  <mtfcc>S1400</mtfcc>
  <streetNumber>649</streetNumber>
  <lat>37.45127</lat>
  <lng>-122.18032</lng>
  <distance>0.04</distance>
  <postalcode>94025</postalcode>
  <placename>Menlo Park</placename>
  <adminCode2>081</adminCode2>
  <adminName2>San Mateo</adminName2>
  <adminCode1>CA</adminCode1>
  <adminName1>California</adminName1>
  <countryCode>US</countryCode>
 </address>
</geonames>
Jeroen Vannevel
  • 43,651
  • 22
  • 107
  • 170
2
var geocoder  = new google.maps.Geocoder();             // create a geocoder object
var location  = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);    // turn coordinates into an object          
geocoder.geocode({'latLng': location}, function (results, status) {
if(status == google.maps.GeocoderStatus.OK) {           // if geocode success
var add=results[0].formatted_address;         // if address found, pass to processing function
document.write(add);

source from https://gist.github.com/marchawkins/9406213/download# it works me

Thamaraiselvam
  • 6,961
  • 8
  • 45
  • 71
0

this is an alternate method. U can use the following google api for getting the address as json script .You can parse the same in your application to get the address.

https://maps.googleapis.com/maps/api/directions/json?origin=27.6325&destination=85.1453=end&sensor=false