High accuracy geolocation Html5

前端 未结 2 929
轮回少年
轮回少年 2020-12-08 01:19

I am tring to locate a device using the embedded GPS (like whats app share location). I\'ve read that it is possible with enableHighAccuracy: true.

How

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-08 02:00

    Here's a simple example of enableHighAccuracy: true taken from the Mozilla Developer Network.

    var options = {
      enableHighAccuracy: true,
      timeout: 5000,
      maximumAge: 0
    };
    
    function success(pos) {
      var crd = pos.coords;
    
      console.log('Your current position is:');
      console.log(`Latitude : ${crd.latitude}`);
      console.log(`Longitude: ${crd.longitude}`);
      console.log(`More or less ${crd.accuracy} meters.`);
    }
    
    function error(err) {
      console.warn(`ERROR(${err.code}): ${err.message}`);
    }
    
    navigator.geolocation.getCurrentPosition(success, error, options);
    

提交回复
热议问题