Javascript 谷歌地图使用PHP、MySQL显示错误的经度值

Javascript 谷歌地图使用PHP、MySQL显示错误的经度值,javascript,php,google-maps,google-maps-api-3,Javascript,Php,Google Maps,Google Maps Api 3,我正在使用谷歌地图标记,它显示了多个位置。代码运行正常,但会自动向long值添加多个数字 例如: XML文件的值为long和lat: Lat:28.4263 Long:77.0477 Map正在从我的数据库中获取上述数据 这是我的index.php,其中包含地图代码: <div id="map"></div> <script> var customLabel = { flat: { label: 'F' }, bar:

我正在使用谷歌地图标记,它显示了多个位置。代码运行正常,但会自动向
long
值添加多个数字

例如:

XML文件的值为long和lat:

Lat:28.4263
Long:77.0477
Map正在从我的数据库中获取上述数据

这是我的
index.php
,其中包含地图代码:

<div id="map"></div>
<script>
  var customLabel = {
    flat: {
      label: 'F'
    },
    bar: {
      label: 'B'
    }
  };

    function initMap() {
    var map = new google.maps.Map(document.getElementById('map'), {
      center: new google.maps.LatLng(20.593788, 78.962988,false),
      zoom: 5
    });
    var infoWindow = new google.maps.InfoWindow;

      // Change this depending on the name of your PHP or XML file
      downloadUrl('map_back.php', function(data) {
        var xml = data.responseXML;
        let geocoder = new google.maps.Geocoder();


        var markers = xml.documentElement.getElementsByTagName('marker');
        Array.prototype.forEach.call(markers, function(markerElem) {
            geocoder.geocode({
          address: markerElem.getAttribute('address')
        }, function(geocoderResults) {
          let latlng = geocoderResults[0].geometry.location; // a LatLng object
          console.log(latlng.lat(), latlng.lng());
        });
          var id = markerElem.getAttribute('id');
          var name = markerElem.getAttribute('name');
          var address = markerElem.getAttribute('address');
          var type = markerElem.getAttribute('type');
          var lats=parseFloat(markerElem.getAttribute('lat'));
          var longs=parseFloat(markerElem.getAttribute('long'));
          var point = new google.maps.LatLng(lats,longs,false);
          alert(point);
          var infowincontent = document.createElement('div');
          var strong = document.createElement('strong');
          strong.textContent = name
          infowincontent.appendChild(strong);
          infowincontent.appendChild(document.createElement('br'));

          var text = document.createElement('text');
          text.textContent = address
          infowincontent.appendChild(text);
          var icon = customLabel[type] || {};
          var marker = new google.maps.Marker({
            map: map,
            position: point,
            label: icon.label

          });
          marker.addListener('click', function() {
            infoWindow.setContent(infowincontent);
            infoWindow.open(map, marker);
          });

        });

      });
    }



  function downloadUrl(url, callback) {
    var request = window.ActiveXObject ?
        new ActiveXObject('Microsoft.XMLHTTP') :
        new XMLHttpRequest;

    request.onreadystatechange = function() {
      if (request.readyState == 4) {
        request.onreadystatechange = doNothing;
        callback(request, request.status);
      }
    };

    request.open('GET', url, true);
    request.send(null);
  }

  function doNothing() {}
</script>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=MYAPIKEY&callback=initMap">
</script>
我尝试使用
.toFixed()
修复十进制值,但它仍然在值后显示多个数字。如何解决此问题?

搜索: 这是google的经度包装函数引入的浮点舍入错误

如果绝对确定纬度在-90和90之间,经度在-180和180之间,可以将true传递给LatLng构造函数的noWrap参数,包装函数将被绕过。

不过要小心——如果您的坐标超出这些界限,一些API功能将被破坏。


var html=[];
var getprice=[];
getprice[]='';
html[]='
“+getprice[]+”;
变量位置=[
];
函数myMap(){
var myCenter=new google.maps.LatLng();
var mapCanvas=document.getElementById(“map1”);
var mapOptions={center:myCenter,zoom:14};
var map=new google.maps.map(mapCanvas,mapOptions);
设置标记(地图、位置)
功能设置标记(地图、位置){
变量标记
对于(i=0;i
我使用的是Google Maps Marker,它使用php、mysql和基于lat的数据库值long显示多个位置的价格显示

你是在问
77.0477
77.0477000000000054
之间的区别吗?我的数据库中有77.0477。。在var point=new google.maps.LatLng。。。。。它更改为77.047700000000054,地图上没有显示正确的位置@geocodezipt,差异将不可见。如果“地图没有显示正确的位置”,那么其他地方就错了。我应该这样做吗var point=new google.maps.LatLng(lats,longs,false)?是的,看起来是这样。这不是一个错误。浮点数并不完全代表数字。@TimDavis我已经更新了代码,但仍然有相同的代码issue@denny对不起,我没有其他建议,但这似乎不是什么问题。。这两个数字之间的差值实际上相差100亿分之一点,这就是浮点运算的原理。也许你应该研究一下为什么你的位置是错的,因为那只会偏离1000米。你能给你的代码添加一些解释吗?你为什么认为它能解决问题?哪些部件是必需的?请不要只发布代码,这使得OP几乎不可能发现他的错误
28.4263, 77.04770000000000054