地理编码 Google 地图和ASP
我正在尝试使用 Classic Asp 从谷歌地图获取地址坐标。
当我在地址栏中写入此地址时,我得到正确的结果:
http://maps.google.com/maps/geo?output=xml&q=32822%20USA
但我得到代码 602(错误)来自谷歌的位置)当我尝试使用 MSXML2.ServerXMLHttp 调用相同的地址时,
asp 代码:
url = "http://maps.google.com/maps/geo?output=xml&q=" & Server.URLEncode("32822 USA")
set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "GET", url, false
xmlhttp.send ""
xml = xmlhttp.responseText
set xmlhttp = nothing
I'm trying to get coordinates of address from google map with Classic Asp.
When I write this address in address bar I get correct result:
http://maps.google.com/maps/geo?output=xml&q=32822%20USA
But I get Code 602 (bad location from google) when I try to call same address with MSXML2.ServerXMLHttp
the asp codes:
url = "http://maps.google.com/maps/geo?output=xml&q=" & Server.URLEncode("32822 USA")
set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "GET", url, false
xmlhttp.send ""
xml = xmlhttp.responseText
set xmlhttp = nothing
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里的问题不在于 URL 的格式是否正确,而在于您无法执行跨域 XMLHttpRequest。您对 Google 地图地理编码服务的请求必须从服务器完成,该服务器将获取 XML 内容并将其返回给您的 ASP 脚本。
我会这样做:您的 ASP 脚本可能会调用一个 PHP 文件,该文件查询 Google 地理编码并使用 cURL 获取响应,并将其返回到 ASP,然后由 ASP 处理它。
如果您不想使用此解决方案,您不妨查看一下也提供地理编码方法的 Google Maps Javascript API (链接)
Your problem here is not the URL, which is correctly formed, but the fact that you cannot do cross-domain XMLHttpRequest. Your request to the Google Maps Geocoding Service must be done from a server, that will fetch the XML content and return it to you ASP script.
Here's what I would do: your ASP script might call a PHP file that queries Google Geocoding and fetches the response with cURL and returns it to the ASP that can then process it.
If you don't want to use this solution, you might as well look at the Google Maps Javascript API that also provides Geocoding methods (link)