HTML 5地理定位用于确定用户的位置。这可以在没有SSL连接的情况下进行。可以按照以下方式生成−
// Variable apigeo shows successful location: var apigeo = function(position) { alert("API geolocation success!lat = " + position.coords.latitude + "lng = " + 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! "+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 }};