首页 > 解决方案 > 使用地理编码器获取纬度和经度,但经度和纬度不准确

问题描述

我首先使用 Place Autocomplete 来获取位置名称,例如 Paris。然后系统检索巴黎的地理位置。但检索到的地理位置是 -77.19452469999999 和 40.337568,这不是巴黎的坐标。

<form>
    <div class=" search-container">
        <input id="autocomplete" placeholder="Enter your address"
         onFocus="geolocate()" type="text" style="width:50%; margin: 1%;" onchange="GetLatlong();" />
        <input type="submit"  class="btn-info" id="submit" name="submit" style="width:50%; margin: 1%; " />
    </div>
</form>

这是Javascript代码

function GetLatlong()
  {
     var geocoder = new google.maps.Geocoder();
     var address = document.getElementById('autocomplete').value;

    geocoder.geocode({ 'address': address }, function (results, status) {

       if (status == google.maps.GeocoderStatus.OK) {
          var latitude = results[0].geometry.location.lat();
          var longitude = results[0].geometry.location.lng();
          // 

   window.location.href="http://localhost/disert/placesautocomplet/index.php? 
   longitude="+ longitude+"&latitude="+latitude;
        alert(longitude);
        alert(latitude);
      }
   });
 }

我怎样才能得到正确的坐标而不是我得到的坐标。

标签: javascripthtmlgoogle-geocoder

解决方案


推荐阅读