HTML 5 Geolocation은 사용자의 위치를 찾는 데 사용됩니다. 이것은 SSL 연결 없이도 가능합니다. 이것은 다음과 같이 생성될 수 있습니다 -
// Variable apigeo shows successful location:
var apigeo = function(position) {
alert("API geolocation success!\n\nlat = " + position.coords.latitude + "\nlng = " + position.coords.longitude);
};
var tryapigeo = function() {
jQuery.post( "check the location on google map", function(success) {
apiGeolocationSuccess({coords: {latitude: success.location.lat, longitude: success.location.lng}});
}) //Gives success on given geolocation
.failure(function(err) { //On failure, alert with failure is shown
alert("error while showing geolocation! \n\n"+err);
});
}; 그러면 오류 코드에 대한 다양한 전환 사례가 생성될 수 있으며, 다른 오류에 대해 다른 오류 코드가 생성될 수 있습니다.
var tryloc = function() {//tryloc variable show current position
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
browserGeolocationSuccess, browserGeolocationFail,{
maximumAge: 70000, timeout: 40000, enableHighAccuracy: true});
/ /this will show result with high accuracy
}};