The WeChat public account can obtain the location of the courier in real time. Is there any good solution or interface?
The WeChat public account can obtain the location of the courier in real time. Is there any good solution or interface?
Html5 itself can obtain the geographical location (WGS-84)
But the premise is that the courier keeps opening that web page without a black screen. After the black screen, the script in the web page will be suspended (so the GPS will also be stopped).
The official account will only read the coordinates and upload them to the background when entering the main interface. After entering the Web page, the permissions will be reduced to the same as HTML.
The JS API of the official account will not continuously obtain the coordinates, unless setInterval keeps fetching them, and the JS will stop after the black screen.
If you need to upload the courier's coordinates to the server in real time, the only way is APP.
The method of obtaining geographical location on the Web: navigator.geolocation has three functions:
<code>void getCurrentPosition(onSuccess,onError,options); //获取用户当前位置 int watchCurrentPosition(onSuccess,onError,options); //持续获取当前用户位置 void clearWatch(watchId); //watchId 为watchCurrentPosition返回的值 //取消监控</code>
<code> function getLocation(){ var options={ enableHighAccuracy:true, maximumAge:1000 } if(navigator.geolocation){ //浏览器支持geolocation navigator.geolocation.watchCurrentPosition(onSuccess,onError,options); }else{ //浏览器不支持geolocation } } //成功时 function onSuccess(position){ //返回用户位置 //经度 var longitude =position.coords.longitude; //纬度 var latitude = position.coords.latitude; } //失败时 function onError(error){ switch(error.code){ case 1: alert("位置服务被拒绝"); break; case 2: alert("暂时获取不到位置信息"); break; case 3: alert("获取信息超时"); break; case 4: alert("未知错误"); break; } } //开始获得 getLocation();</code>
How to convert WGS-84 to Tencent/Baidu coordinates, please go to https://www.oschina.net/code/...