Computer >> Máy Tính >  >> Lập trình >> HTML

Định vị địa lý HTML5 không có kết nối SSL


HTML 5 Vị trí địa lý được sử dụng để tìm ra vị trí của người dùng. Điều này có thể không có kết nối SSL. Điều này có thể được tạo như sau -

// 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);
   });
};

Sau đó có thể tạo ra nhiều trường hợp chuyển đổi khác nhau cho các mã lỗi, các mã lỗi khác nhau cho các lỗi khác nhau.

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
}};