Javascript 地理编码不能准确地确定谷歌地图上的点位置
在谷歌地图中,当我拖动文本框中显示的标记Javascript 地理编码不能准确地确定谷歌地图上的点位置,javascript,google-maps,google-maps-api-3,google-maps-markers,geocoding,Javascript,Google Maps,Google Maps Api 3,Google Maps Markers,Geocoding,在谷歌地图中,当我拖动文本框中显示的标记lat()和lng()值时。我想喜欢这里: 我的以下代码部分为我工作。但是,当我将标记拖到远处时,它会工作,但是在 小距离lat()和lng()不会改变吗 我如何解决这个问题 主要js代码为: // fill in the UI elements with new position data function update_ui(address, lat, lng) { $('#lat').val(lat)
lat()
和lng()
值时。我想喜欢这里:
我的以下代码部分为我工作。但是,当我将标记拖到远处时,它会工作,但是在
小距离lat()
和lng()
不会改变吗
我如何解决这个问题
主要js代码为:
// 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)
}
和地理编码:
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())
}
};
});
编辑:
当我稍微拖动一个标记时,坐标不会改变,但经过一些移动后,坐标会改变。以下是JSFIDLE:
问题是您正在通过地理编码器传递标记的位置 地理编码器获取原始lat/lng位置并尝试将其映射到地址。这可能是一条街道、一个城镇或一个地区。Google geocoder返回的结果包括地址文本以及该地址的位置 您正在显示地理编码器返回的位置。当用户在潜在地址密度较低的区域移动标记时,您将看到别名。这意味着用户“选择”的各种原始位置将把地理编码向下反转到地理编码器返回的相同地址 因此,当您实际执行的是显示地理编码地址的lat/lng时,标记的lat/lng似乎没有改变
请注意,您链接到的站点在显示位置信息时不会进行任何地理编码。您是否有显示此问题的链接或JSFIDLE?不能用图片做任何事情。更新的价值是什么?更新映射做什么?不,对不起,我不能将代码添加到JSFIDLE。我编辑了我的问题,添加了那个函数。现在我正在学习。google.maps.GeocoderLocationType.roottop。这是一种地理编码器能够精确地找到点的类型。但我不能将该类型设置为geocoder。@geocodezip,我将代码放在JSFIDLE并编辑了我的问题。你们能帮我吗?我能用什么,当移动标记时,地图上每个点的坐标都会改变。因为我将标记坐标保存在数据库中,然后加载它们,它们看起来不在真实的位置。他们逃跑了。这听起来像是一个完全不同的问题-所以问一个新的问题。不能做什么?我不明白你在问什么。对不起,我的英语不好。当标记移动一点时,我需要显示更改的坐标,但是用我的代码我不能得到那个结果。一般来说,可以用谷歌地理编码器来做吗?如果可能的话,我怎样才能修改我的代码,如果不行,我会问一个新问题。正如我解释的,你不能依赖地理编码器。然而,您已经有了原始位置,因为这是您首先传递给地理编码器的内容,所以请使用它!