模拟GPS位置和Android的Chrome [英] Mock GPS location and Chrome for Android

查看:176
本文介绍了模拟GPS位置和Android的Chrome的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Trimble ProXT GNSS接收器,它具有蓝牙功能,可以使用Trimble GNSS状态应用程序连接到Android。该应用程序输出基本单元的位置,如果我选择该应用程序作为开发人员选项中的模拟位置提供程序,它在所有本机应用程序中效果很好,但如果我尝试使用使用html5地理位置API的Web应用程序,则会失败。我的GIS数据采集应用程序是基于网络的,我需要这个工作!

解决方案

使用TrimbleGNSS状态并且遇到同样的问题,包括ipad + chrome和各种android + chrome组合,而firefox和safari都能正常工作。



进行简单测试:

 < DOCTYPE html> 
< html>
< head>
< style>
body {
background:white;
font-family:Arial,Helvetica,sans-serif;
font-size:1em;
颜色:#000;
}
@media all和(max-width:1000px){
body {font-size:200%;}
}
< / style>
< script>
函数init(){
var compass = document.getElementById('compass');
var lat = document.getElementById('lat');
var lon = document.getElementById('lon');
var acc = document.getElementById('acc');
var alt = document.getElementById('alt');
var altAcc = document.getElementById('altAcc');
var err = document.getElementById('err');
var heading = document.getElementById('heading');
var speed = document.getElementById('speed');
var timestamp = document.getElementById('timestamp');

if(window.DeviceOrientationEvent){
window.addEventListener('deviceorientation',function(event){
var alpha;
if(event.webkitCompassHeading){
alpha = event.webkitCompassHeading;
}
else {
alpha = event.alpha;
}
compass.innerHTML = alpha;
},false);

$ b $ if(navigator.geolocation){
var opts = {
enableHighAccuracy:true,
timeout:6000,
maximumAge: 5000
};
navigator.geolocation.watchPosition(
updateLocation,
handleLocationError,
opts
);
}
}

函数updateLocation(position){
lat.innerHTML = position.coords.latitude;
lon.innerHTML = position.coords.longitude;
acc.innerHTML = position.coords.accuracy;
alt.innerHTML = position.coords.altitude;
altAcc.innerHTML = position.coords.altitudeAccuracy;
heading.innerHTML = position.coords.heading;
speed.innerHTML = position.coords.speed;
var t = new Date(position.timestamp).toString();
timestamp.innerHTML = t;
addMsg(t);
}

函数handleLocationError(e){
var msg = e.code +':';
switch(e.code){
case error.PERMISSION_DENIED:
msg + ='权限被拒绝';
休息;
case error.POSITION_UNAVAILABLE:
msg + ='位置当前不可用。';
休息;
case error.PERMISSION_DENIED_TIMEOUT:
msg + ='用户花了很长时间来授予/拒绝权限。
休息;
case error.UNKNOWN_ERROR:
msg + ='发生未知错误。
休息;
}
addMsg(msg);


函数addMsg(msg){
err.appendChild(document.createTextNode('message:'+ msg));
err.appendChild(document.createElement(br));
}
< / script>
< / head>
< body onload =init()>
< p>指南针:< span id =compass>< / span>度< / p为H.
< hr>
< p> lat:< span id =lat>< / span>度< / p为H.
< p> lon:< span id =lon>< / span>度< / p为H.
< p> acc:< span id =acc>< / span> M< / p为H.
< p> alt:< span id =alt>< / span> m + msl< / p>
< p> alt。 acc:< span id =altAcc>< / span> M< / p为H.

< p>标题:< span id =heading>< / span>度< / p为H.
< p>速度:< span id =speed>< / span>米/秒< / p为H.
< p>时间戳:< span id =timestamp>< / span>< / p>
< hr>
< p>条消息:< / p>
< div id =err>< / div>
< / body>
< / html>


I have a Trimble ProXT GNSS receiver that has Bluetooth and can connect to android using the Trimble GNSS Status app. The app outputs the location of the base unit and if I select the app as the mock location provider in developer options it works great in all native apps but if I try using a web app that's using the html5 geo location API it fails. My GIS data acquisition app is web based and I need this to work!

解决方案

Using Trimble "GNSS status" app with an R2 and running into the same problems om both ipad+chrome and various android+chrome combinations while firefox and safari work ok.

for a simple test:

<DOCTYPE html>
<html>
  <head>
    <style>
      body {
          background: white;
          font-family: Arial, Helvetica, sans-serif;
          font-size: 1em;
          color: #000;
      }
      @media all and (max-width: 1000px) {
          body { font-size: 200%;}
      }
    </style>
    <script>
      function init() {
        var compass = document.getElementById('compass');
        var lat = document.getElementById('lat');
        var lon = document.getElementById('lon');
        var acc = document.getElementById('acc');
        var alt = document.getElementById('alt');
        var altAcc = document.getElementById('altAcc');
        var err = document.getElementById('err');
        var heading = document.getElementById('heading');
        var speed = document.getElementById('speed');
        var timestamp = document.getElementById('timestamp');

        if(window.DeviceOrientationEvent) {
            window.addEventListener('deviceorientation', function(event) {
                var alpha;
                if(event.webkitCompassHeading) {
                  alpha = event.webkitCompassHeading;
                }
                else {
                  alpha = event.alpha;
                }
                compass.innerHTML = alpha;
            }, false);
        }

        if(navigator.geolocation) {
            var opts = {
                        enableHighAccuracy: true,
                        timeout: 6000,
                        maximumAge: 5000
                       };
            navigator.geolocation.watchPosition(
                    updateLocation,
                    handleLocationError,
                    opts
            );
        }
      }

    function updateLocation(position) {
        lat.innerHTML = position.coords.latitude;
        lon.innerHTML = position.coords.longitude;
        acc.innerHTML = position.coords.accuracy;
        alt.innerHTML = position.coords.altitude;
        altAcc.innerHTML = position.coords.altitudeAccuracy;
        heading.innerHTML = position.coords.heading;
        speed.innerHTML = position.coords.speed;
        var t = new Date(position.timestamp).toString();
        timestamp.innerHTML = t;
        addMsg(t);
    }

    function handleLocationError(e){
      var msg = e.code+': ';
      switch (e.code) {
          case error.PERMISSION_DENIED:
              msg += 'Permission was denied';
              break;
          case error.POSITION_UNAVAILABLE:
              msg +='Position is currently unavailable.';
              break;
          case error.PERMISSION_DENIED_TIMEOUT:
              msg += 'User took to long to grant/deny permission.';
              break;
          case error.UNKNOWN_ERROR:
              msg += 'An unknown error occurred.';
              break;
      }
      addMsg(msg);
    }

    function addMsg(msg){
      err.appendChild(document.createTextNode('message: '+ msg));
      err.appendChild(document.createElement("br"));
    }
    </script>
  </head>
  <body onload="init()" >
      <p>compass: <span id="compass"></span> deg</p>
      <hr>
      <p>lat: <span id="lat"></span> deg</p>
      <p>lon: <span id="lon"></span> deg</p>
      <p>acc: <span id="acc"></span> m</p>
      <p>alt: <span id="alt"></span> m +msl</p>
      <p>alt. acc: <span id="altAcc"></span> m</p>

      <p>heading: <span id="heading"></span> deg</p>
      <p>speed: <span id="speed"></span> m/s</p>
      <p>timestamp: <span id="timestamp"></span></p>
      <hr>
      <p>messages:</p>
      <div id="err"></div>
  </body>
</html>

这篇关于模拟GPS位置和Android的Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆