gpt4 book ai didi

jquery - Google map 地理编码和 ZERO_RESULTS

转载 作者:行者123 更新时间:2023-12-02 17:40:19 25 4
gpt4 key购买 nike

我已经将我之前为另一个 Web 应用程序编写的代码用于另一个。但是,没有明显的原因,它没有检索结果:

Geocode was not successful for the following reason: ZERO_RESULTS

我有以下代码,正如所暗示的那样,它可以在其他地方正常运行:

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script type="text/javascript">
function googleMaps (lat, lng, zoom) {
geocoder = new google.maps.Geocoder();
var myLatlng = new google.maps.LatLng(lat, lng);
var myOptions = {
zoom: zoom,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.TERRAIN
}
map = new google.maps.Map(document.getElementById("map-locations"), myOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map
});
google.maps.event.addListener(map, "center_changed", function(){
document.getElementById("latitude").value = map.getCenter().lat();
document.getElementById("longitude").value = map.getCenter().lng();
marker.setPosition(map.getCenter());
document.getElementById("zoom").value = map.getZoom();
});
google.maps.event.addListener(map, "zoom_changed", function(){
document.getElementById("zoom").value = map.getZoom();
});
}
$(document).ready(function() {
googleMaps(52.3555, -1.1743, 6);
});
</script>
<script>
$(document).ready(function(){
$("#address").change(function(){
geocoder.geocode({
"address": $(this).attr("value")
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setZoom(14);
map.setCenter(results[0].geometry.location);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
});
})
</script>

我还有“ Canvas ”和相应的地址字段,它们与其他地方的功能版本相同。

顺便说一句,我通过 Google API 程序创建了一个 API key ,我认为这与早期版本无关。但是有或没有 API key ,它都不会起作用。

所以我想知道这个过程是否以某种方式破坏了东西。

最佳答案

您必须将代码更改为

...
geocoder.geocode({
"address": $("#address").val()
}, function(results, status) {
...

使用 $("#address").val() 而不是 $("#address").attr("value")

更新:另见 SO 问题 jQuery $obj.val() vs $obj.attr(“value”)

关于jquery - Google map 地理编码和 ZERO_RESULTS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21699939/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com