Created
June 4, 2013 08:40
-
-
Save hieutran/5704541 to your computer and use it in GitHub Desktop.
Javascript Ajax Geo-location
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Javascript Ajax Geo-location</title> | |
<script src="http://code.google.com/apis/gears/gears_init.js" type="text/javascript" charset="utf-8"></script> | |
<script src="js/geo.js?id=1" type="text/javascript" charset="utf-8"></script> | |
</head> | |
<body> | |
<b>Javascript geo sample</b> | |
<script> | |
if(geo_position_js.init()) { | |
geo_position_js.getCurrentPosition(success_callback,error_callback,{enableHighAccuracy:true}); | |
} | |
else{ | |
if( console && console.log ) { | |
console.log("Geo-location functionality not available"); | |
} | |
} | |
function success_callback(p) { | |
$.ajax({ | |
url: "geolocation.php", | |
type: "POST", | |
data: {lat: p.coords.latitude.toFixed(2), lon: p.coords.longitude.toFixed(2)} | |
}).done(function (data) { | |
if( console && console.log ) { | |
console.log("Saved user geo-location data: lat=" + data.lat + ";lon=" + data.lon)); | |
} | |
}); | |
} | |
function error_callback(p) { | |
if( console && console.log ) { | |
console.log("error=" + p.code); | |
} | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment