DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> <p>Click the button to get your coordinates.</p> <button onclick="getLocation()">Try It</button> <p id="demo"></p> <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script> <script type="text/javascript"> var x = document.getElementById("demo"); var Latitudevar; var Longitudevar; function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition); } else { x.innerHTML = "Geolocation is not supported by this browser."; } } function showPosition(position) { x.innerHTML = "Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude; Latitudevar = position.coords.latitude; Longitudevar = position.coords.longitude; GetAddress(); } function GetAddress() { var lat = Latitudevar; var lng = Longitudevar; var latlng = new google.maps.LatLng(lat, lng); var geocoder = geocoder = new google.maps.Geocoder(); geocoder.geocode({ 'latLng': latlng }, function (results, status) { if (status == google.maps.GeocoderStatus.OK) { if (results[1]) { // alert("Location: " + results[1].formatted_address); x.innerHTML = "Area: " + results[1].formatted_address; } } }); } </script> </body> </html>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)