How do I get location name or city using latitude & longitudes?
Asked Answered
W

1

13

I'm using the below code, but how to get the city name or the location name from the longitude & latitude?

var x=document.getElementById("location");
function getLocation()
{
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition,showError);
    }
    else {
        x.innerHTML="Geolocation is not supported by this browser.";
    }
}

function showPosition(position)
{
    x.innerHTML="Latitude: " + position.coords.latitude + 
        "<br>Longitude: " + position.coords.longitude;  
}
Wring answered 27/3, 2013 at 15:29 Comment(2)
en.wikipedia.org/wiki/Reverse_geocodingConsul
try the Google Geocoding API developers.google.com/maps/documentation/geocodingCatholicity
C
8

You can use the Google Maps v3 API to perform reverse geocoding on a latitude and longitude pair. You can find an example of how to do that here: https://developers.google.com/maps/documentation/geocoding/#ReverseGeocoding.

Codicodices answered 27/3, 2013 at 15:32 Comment(1)
But location name doesn't appearNonintervention

© 2022 - 2024 — McMap. All rights reserved.