Mock GPS location and Chrome for Android

霸气de小男生 提交于 2020-01-16 12:03:20

问题


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!


回答1:


I ran into this same issue and was able to get some help from Trimble:

I'm assuming you're working on Android, as that's where we've seen this behavior as well. What you've noticed is an odd behavior characteristic of Google Chrome unfortunately. You'll find that if you use the Firefox browser (or several others) and visit the same maps.google.com, the location will display properly.

Inexplicably, the Chrome implementation of the Location API doesn't handle mock locations in all cases. We have an ongoing investigation into this on our end, but no formal resolution exists so far (aside from the non-Chrome browser workaround).




回答2:


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>


来源:https://stackoverflow.com/questions/39214630/mock-gps-location-and-chrome-for-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!