地理编码不会完全确定谷歌地图上的点位置 [英] geocode does not determine point location exactly on google map

查看:168
本文介绍了地理编码不会完全确定谷歌地图上的点位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在google map中,当我拖动文本框中显示的 lat() lng()值时。我想要喜欢这里:



每个运动的坐标变化



我的下列代码部分适用于我。但是,当我将一个标记拖到远处时,它可以正常工作,但在 lat()和 lng()不更改?

我该如何解决这个问题?

主要的js代码有:

  //用新的位置数据填充UI元素
function update_ui(address,lat,lng){
$('#lat ).VAL(LAT);
$('#lng')。val(lng);
}


//将标记移动到一个新的位置,并将地图放在它的中心
function update_map(geometry){
map.fitBounds (geometry.viewport)
marker.setPosition(geometry.location)
}

和地理编码:

  geocoder.geocode(request,function(results,status){
if(status == google.maps.GeocoderStatus.OK){
// Google地理编码成功!
if(results [0]){
//总是用新的位置数据更新UI元素
update_ui(results [0] .formatted_address,results [0] .geometry.location.lat(),results [0] .geometry.location.lng())

//只更新地图(位置标记和中心图)如果请求
if(update){update_map(results [0] .geometry)}
} else {
// Ge ocoder状态好但没有结果!?
alert(发生错误,请重试。);
}
}其他{
// Google地理编码失败。两个常见原因:
// *地址未被识别(例如,搜索'zxxzcxczxcx')
// *地点未映射到地址(例如,在大西洋中部点击)

if(type =='address'){
alert(对不起!我们找不到+ value +。尝试一个不同的搜索词,或点击地图。
} else {
alert(对不起!我们找不到+ value +。尝试一个不同的搜索词,或点击地图。
update_ui('',value.lat(),val.lng())
}
};
});

编辑:

当我很少拖动一个标记时,坐标不会改变,但是在一些移动之后它们会改变。这里是jsfiddle:



http://jsfiddle.net / jhoonbey / wwdE9 /

解决方案

问题是您要通过地理编码器传递标记的位置。



地理编码器采用原始纬度/经度位置并尝试将其映射到地址。这可能是一条街道,一个城镇或一个地区。 Google地理编码返回的结果包括地址文本以及该地址的位置。



您显示地理编码返回的位置。当用户在潜在地址密度较低的区域周围移动标记时,您将看到别名。这意味着用户'选择'的各种原始位置会将地理编码反转为由地址解析器返回的相同地址。



因此,它看起来好像是标记的纬度/经度不会改变,当您实际做的是显示地理编码地址的纬度/经度。



请注意,您链接的网站在显示位置信息时不会进行任何地理编码。


In google map when I drag a marker lat() and lng() values shown in textboxes. I want do to like here:

Coordinates change for every movement

My following code parts work for me. But, when I drag a marker to far, it works, but in little distances lat() and lng() don't change?

How can I solve this issue?

main js codes are:

// fill in the UI elements with new position data
            function update_ui(address, lat, lng) {
            $('#lat').val(lat);
            $('#lng').val(lng);
        }


 // move the marker to a new position, and center the map on it
        function update_map(geometry) {
            map.fitBounds(geometry.viewport)
            marker.setPosition(geometry.location)
        }

And geocode:

geocoder.geocode(request, function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                // Google geocoding has succeeded!
                if (results[0]) {
                    // Always update the UI elements with new location data
                    update_ui(results[0].formatted_address, results[0].geometry.location.lat(), results[0].geometry.location.lng())

                    // Only update the map (position marker and center map) if requested
                    if (update) { update_map(results[0].geometry) }
                } else {
                    // Geocoder status ok but no results!?
                    alert("Error occured. Please try again.");
                }
            } else {
                // Google Geocoding has failed. Two common reasons:
                //   * Address not recognised (e.g. search for 'zxxzcxczxcx')
                //   * Location doesn't map to address (e.g. click in middle of Atlantic)

                if (type == 'address') {
                    alert("Sorry! We couldn't find " + value + ". Try a different search term, or click the map.");
                } else {
                    alert("Sorry! We couldn't find " + value + ". Try a different search term, or click the map.");
                    update_ui('', value.lat(), val.lng())
                }
            };
        });

Edit:

When I drag a marker very little, coordinates do not change, but after some movement they change. Here is jsfiddle:

http://jsfiddle.net/jhoonbey/wwdE9/

解决方案

The problem is that you're passing the marker's position through a geocoder.

A geocoder takes a raw lat/lng location and tries to map it to an address. This could be a street or a town or a region. The results that the Google geocoder return include the address text, plus the location of that address.

You're displaying the location that the geocoder returns. As the user moves the marker around regions with a low density of potential addresses, you're going to see aliasing. That means that the various raw locations that the user 'selects' will reverse geocode down to the same address being returned by the geocoder.

Thus, it will appear as if the lat/lng of the marker is not changing, when what you're actually doing is displaying the lat/lng of the geocoded address.

Note, that site that you linked to doesn't do any geocoding when it displays position information.

这篇关于地理编码不会完全确定谷歌地图上的点位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆