Home
> Uncategorized > Get your latitude and longitude in Javascript
Get your latitude and longitude in Javascript
Here’s an AJAX request that gets your longitude and latitude in javascript. It’s using XML, not JSON, since there was some problems using eval() for non-US addresses.
var strUrl = “http://maps.googleapis.com/maps/api/geocode/xml?”;
strUrl += “address=bt489ph “;
strUrl += “&sensor=false”;
ajaxRequest = new XMLHttpRequest();
ajaxRequest.onreadystatechange = function() {
if (ajaxRequest.readyState != 4)
{
return;
};
var xmlDoc = ajaxRequest.responseXML;
var latitude = xmlDoc.getElementsByTagName(‘lat’)[0].firstChild.nodeValue;
var longditude = xmlDoc.getElementsByTagName(‘lng’)[0].firstChild.nodeValue;
alert(latitude);
alert(longditude);
};
ajaxRequest.open(“GET”,strUrl,true);
ajaxRequest.send(null);
Categories: Uncategorized
Comments (0)
Trackbacks (0)
Leave a comment
Trackback