简体   繁体   English

Google Maps Geocoder返回未找到

[英]Google maps geocoder returns Not found

I'm trying to use the geocoder to get co-ordinates for the following address: 我正在尝试使用地址解析器来获取以下地址的坐标:

1945 Barton Street, Hamilton, ON, L8H2Y7

Searching the address on google maps itself finds the address: http://g.co/maps/5axb5 . 在Google Maps本身上搜索地址会找到该地址: http : //g.co/maps/5axb5 Using the geocode url also returns fine. 使用地址解析网址也可以正常返回。 http://maps.googleapis.com/maps/api/geocode/json?address=1945+BARTON+STREET,+HAMILTON,+ON,+L8H2Y7&sensor=false http://maps.googleapis.com/maps/api/geocode/json?address=1945+BARTON+STREET,+HAMILTON,+ON,+L8H2Y7&sensor=false

However, when I use the api (my code below), it returns not found. 但是,当我使用api(下面的代码)时,找不到它。

图片

Code: (this works fine for several other addresses I'm searching) 代码:(这对于我正在搜索的其他几个地址都适用)

if (geocoder) {
    geocoder.geocode( {'address': fullAddress }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            map.setCenter(results[0].geometry.location);
            var marker = new google.maps.Marker({
                map: map,
                position: results[0].geometry.location
            });
        } else {
            alert("Geocoding failed: " + status + "  " + fullAddress);
        }
    });
}

The "actual" address is "1945 Barton Street East , Hamilton, ON L8H2Y7, Canada", but maps and the direct url still find the place fine, only the geocoder doesn't. “实际”地址是“加拿大1895 Barton Street East ,汉密尔顿,安大略省L8H2Y7”,但是地图和直接网址仍然可以找到该地点,只有地理编码器找不到。

Any ideas as to why this might be happening? 关于为什么会发生这种情况的任何想法?

EDIT: I figured it out. 编辑:我想通了。 It was a different address that it legitimately couldn't find (not on google maps or using the geocoder), but because the request was being done asynchronously by the time the geocoder realized it couldn't find the address, the loop had already changed the address value to another address which it could find. 它是合法找不到的另一个地址(不在Google地图上或使用地址解析器),但是由于请求是在地址解析器意识到无法找到地址时以异步方式完成的,因此循环已更改地址值到它可以找到的另一个地址。 Seems like I've got some work ahead of me.. 似乎我还有很多工作要做。

it's strange because it work's on my live demo check this 这很奇怪,因为它在我的现场演示中正常工作

Live Demo 现场演示

Do you have more code somewhere?? 您在某处还有更多代码吗?

Update 更新资料

I test the service with the plus symbol, and even without canada and still worked 我使用加号来测试服务,即使没有加拿大也可以使用

here's examples 这是例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM