Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the latitude and longitude using javascript

I am using javascript for the first time.Actually i want to get the latitude and longitude of an address using java script.Can anyone guide me..

like image 920
Aditi Sharma Avatar asked Dec 21 '22 20:12

Aditi Sharma


1 Answers

If you need latitude and longitude of a given adress, you can use google maps api https://developers.google.com/maps/documentation/javascript/

Here is an example: https://google-developers.appspot.com/maps/documentation/javascript/examples/geocoding-simple

EDIT: to display it in an alert popup:

var address = document.getElementById("address").value;
var geocoder = new google.maps.Geocoder();

geocoder.geocode( { 'address': address}, function(results, status) {
  var location = results[0].geometry.location;
  alert(location.lat() + '' + location.lng());
});
like image 125
Jerome Cance Avatar answered Dec 23 '22 10:12

Jerome Cance