谷歌地图将在短距离内输出不准确的坐标

时间:2014-07-26 20:57:03

标签: javascript google-maps google-maps-api-3

我使用谷歌地图通过拖放标记来存储我的数据库中的一些位置坐标

这是我如何做到的:

关于api:

        google.maps.event.addListener(marker_0, "dragend", function(event) {
            updatePosition(event);
        });

这是函数

    function updatePosition(evt){

    console.log(evt.latLng.lat().toFixed(3)+' # '+evt.latLng.lng().toFixed(3));

    var lt =  evt.latLng.lat().toFixed(3) ;
    var lg =  evt.latLng.lng().toFixed(3) ;

    // posting to database  

    }

它几乎可以正常工作,但近距离非常不准确

您可以看到的第一张图片将输出40.714 # -74.009

enter image description here

街道另一边的第二张图片也会输出40.714 # -74.009

enter image description here

我必须一直走到这里,看它改变

enter image description here

所以,如果我使用40.714 , -74.009加载地图,试图展示spa,它可以在街道上显示bus stophairstyle

无论如何,即使是短距离也能获得准确的位置?

1 个答案:

答案 0 :(得分:1)

3位小数等于约100米See。为了您的目的,您需要6位小数。

function updatePosition(evt){

    console.log(evt.latLng.lat().toFixed(6)+' # '+evt.latLng.lng().toFixed(6));

    var lt =  evt.latLng.lat().toFixed(6) ;
    var lg =  evt.latLng.lng().toFixed(6) ;

    // posting to database  

    }