纬度和经度捕获问题

时间:2018-06-14 10:38:07

标签: javascript

我们正在使用Google Java Script API在我们的应用中收集纬度和经度(X和Y坐标)。捕获前15点(X和Y坐标点)时,一切正常。在15点之后我们获得相同的纬度和经度。纬度和经度不会改变。它显示相同的纬度和经度。我使用以下代码:

<script>


      var map, infoWindow;
      function initMap() {
        map = new google.maps.Map(document.getElementById('map'), {
          center: {lat: -34.397, lng: 150.644},
          zoom: 6
        });
        infoWindow = new google.maps.InfoWindow;

        // Try HTML5 geolocation.
        if (navigator.geolocation) {
          navigator.geolocation.getCurrentPosition(function(position) {
            var pos = {
              lat: position.coords.latitude,
              lng: position.coords.longitude
            };
            var reslat = pos.lat;
            var reslng = pos.lng;
alert('X-'+reslat + ' &Y-'+reslng);

//alert(reslng);
document.getElementById('reslat').value = reslat;
document.getElementById('reslng').value = reslng;
            infoWindow.setPosition(pos);
            infoWindow.setContent('Location found.');
            infoWindow.open(map);
            map.setCenter(pos);
          }, function() {
            handleLocationError(true, infoWindow, map.getCenter());
          });
        } else {
          // Browser doesn't support Geolocation
          handleLocationError(false, infoWindow, map.getCenter());
        }
      }

      function handleLocationError(browserHasGeolocation, infoWindow, pos) {
        infoWindow.setPosition(pos);
        infoWindow.setContent(browserHasGeolocation ?
                              'Error: The Geolocation service failed.' :
                              'Error: Your browser doesn\'t support geolocation.');
        infoWindow.open(map);
      }

    </script>
    <script async defer
    src="https://maps.googleapis.com/maps/api/js?key=myapikey=initMap">
    </script>

0 个答案:

没有答案