API HTML5 , (GPS), IP- , , . , API , , .
- HTML5 Geolocation (http://html5demos.com/geo). , - , API, , API .
API :
getCurrentPosition (successCallback, errorCallback, options)
.
watchPosition (successCallback, errorCallback, options)
watchId successCallback . (, GPS ).
clearWatch (watchId)
watchPosition() watchId.
:
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(userPositionSuccess, userPositionError);
} else {
alert("Your browser does not support geolocation.");
}
function userPositionSuccess(position) {
alert("Latitude: " + position.coords.latitude + " Longitude: " + position.coords.longitude);
}
function userPositionError() {
alert("There was an error retrieving your location!");
}