如何使用 jquery ajax 调用 google 地图地理编码服务
我正在尝试从谷歌地图地理编码 api 获取 LatLng。我的代码如下,地址值为“纽约,纽约”,
$.ajax({
url: 'http://maps.googleapis.com/maps/api/geocode/json',
data: {
sensor: false,
address: address
},
success: function (data) {
alert(data)
}
});
但我没有收到任何警报值。
感谢您的任何帮助。
I'm trying to get the LatLng from google map geocode api. my code is below with address values is "New York, NY"
$.ajax({
url: 'http://maps.googleapis.com/maps/api/geocode/json',
data: {
sensor: false,
address: address
},
success: function (data) {
alert(data)
}
});
But I'm not getting any values in alert.
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您需要联系 API 了解规则。
编辑:
我真蠢,早上不应该出现在 stackoverflow 上!问题是跨域请求。出于安全原因,这是不允许的。请参阅:如何进行跨域 AJAX 调用到 Google Maps API?
请使用 Google 自己的 地理编码客户端。
You will need to contact the API regarding the rules.
Edit:
How dumb of me, shouldn't be on stackoverflow in the morning! The problem is a cross-domain request. For security reasons this is not allowed. See: How to make cross-domain AJAX calls to Google Maps API?
Please use Google's own Geocoding client.
无需使用 jquery,Google 地图 javascript API v3 内置了自己的功能,这使得该 API 易于使用。
https://developers.google.com/maps/documentation/javascript/geocoding
https://developers.google.com/maps/documentation/geocoding/intro
there is no need to make use of jquery, Google maps javascript API v3 has build in its own functions which makes the API easy to use.
https://developers.google.com/maps/documentation/javascript/geocoding
https://developers.google.com/maps/documentation/geocoding/intro
如果有人在这个话题上寻求帮助,我就是这么做的。请注意,这是反向查找,但正向查找应该以相同的方式工作:
`
If anyone is seeking help on this topic, this is how I have done it. Note this is a reverse lookup, but a forward lookup should work the same way:
`
V3 地理编码 Web 服务不支持 JSONP 请求,但在 V2 中仍然可用
请参阅:http://blog.futtta.be/2010/04/09/no-more-jsonp-for-google-geocoding-webservice/
V3 geocoding webservice doesn't support JSONP requests, but it's still available in V2
See: http://blog.futtta.be/2010/04/09/no-more-jsonp-for-google-geocoding-webservice/
我就是这样做的。地理编码器似乎正在创建它自己的回调。
This is how I did it. Geocoder seems like is creating it's own callback.
或者指定 dataType 为 jsonp?
or specify dataType to jsonp?