【问题标题】:Google API I can't get my position I get just another positionGoogle API 我无法获得我的职位 我只是获得了另一个职位
【发布时间】:2016-03-08 17:59:21
【问题描述】:

我不能得到我的位置,我不知道为什么,只是我得到了另一个位置

我的代码在这里:

<body>
<div id="map"></div>
<script>

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

    // Try HTML5 geolocation.
    if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(function(position) {
        var pos = {
          lat: position.coords.latitude,
          lng: position.coords.longitude
        };

        infoWindow.setPosition(pos);
        infoWindow.setContent('Location found.');
        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.');
  }
</script>

【问题讨论】:

    标签: javascript html google-maps


    【解决方案1】:

    对我来说,如果我允许地理定位请求,您的代码会指示我当前的位置。 如果你的当前位置不正确,那就是 HTML5 Geolocation API 的问题。与 Google Maps API 无关。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-15
      • 2021-05-13
      • 2019-10-30
      • 1970-01-01
      • 2020-09-22
      相关资源
      最近更新 更多