使用 Google 地图 API 进行反向地理编码
我找到了用于反向地理编码的代码:
var point = new GLatLng (lat[1],long[1]);
var geocoder = new GClientGeocoder();
geocoder.getLocations (point, function(result) { alert (lat[1]+' '+long[1]+' '+result.address); });
但它弹出警报,说 result.address 是“未定义”。任何想法,可能是什么问题?
编辑:成功了,谢谢。
I have found this code for reverse geocoding:
var point = new GLatLng (lat[1],long[1]);
var geocoder = new GClientGeocoder();
geocoder.getLocations (point, function(result) { alert (lat[1]+' '+long[1]+' '+result.address); });
But it pops the alert, saying that result.address is 'undefined'. Any ideas, what could be the problem?
EDIT: Got it working, thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你能包括“纬度”和“经度”的定义吗?另外,“long”是保留关键字,因此这可能是一个拼写错误/错误。
此外,返回的结果(至少以 gmaps v2 json 格式)具有更复杂的结构,并且“result.address”不会有任何内容。当我测试它时,我需要使用以下内容访问其中一个地址:
result.Placemark[0].address
see http://code.google.com/apis/maps/documentation/geocoding/index.html#GeocodingResponses
can you include the definitions of 'lat' and 'long'? also, 'long' is a reserved keyword, so that is likely a typo / bug.
also, the results that come back, at least in gmaps v2 json format, have a more complex structure, and 'result.address' won't have anything. when I tested it out, I needed to access one of the addresses with something like:
result.Placemark[0].address
see http://code.google.com/apis/maps/documentation/geocoding/index.html#GeocodingResponses
由此我只能看出
result
没有被传递给函数或者它不是一个对象。您需要查看回调函数接收哪些参数。文档是这样说的:
如果您使用 Firebug,您可以通过以下方式查看传递给回调的内容:
From this I can only tell that
result
is not being passed to the function or it is not an object.You need to see what parameters the callback function receives. Here's what the documentation says:
If you're using Firebug, you can see what's being passed to the callback this way: