无 SSL 连接的 HTML5 地理位置
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); }); };
然后,可以针对错误代码生成各种 switch case,不同的错误代码对应不同的错误。
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 }};
广告