Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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;  
}
like image 280
user2216267 Avatar asked Mar 27 '13 15:03

user2216267


People also ask

How do I find a location using latitude?

To find a location using its latitude and longitude on any device, just open Google Maps. On your phone or tablet, start the Google Maps app. On a computer, go to Google Maps in a browser. Then enter the latitude and longitude values in the search field — the same one you would ordinarily use to enter an address.

How do I find an address using latitude and longitude?

On the Google Maps app, you can't pull up a context menu. To find the address for your coordinates, hold your finger down over the red pin that shows your coordinates. Then, after 1-3 seconds, the address will pop up on the bottom of your screen.


1 Answers

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.

like image 165
RouteMapper Avatar answered Nov 15 '22 15:11

RouteMapper