错误地理编码API

时间:2014-03-18 13:27:44

标签: c# geocoding google-geocoder

我正在尝试使用谷歌地理编码。如果我只是输入

https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true

它给了我正确的输出。我正在尝试将它与亚马逊代理服务器一起使用,它提供了

{ "error_message" : "The 'sensor' parameter specified in the request must be set to either 'true' or 'false'.", "results" : [], "status" : "REQUEST_DENIED" }

这个代码

http://ec2-00-000-000-000.compute-1.amazonaws.com/OsProxy/getpage.aspx?p=https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true

有人可以帮助我吗?

由于 Rashmi

1 个答案:

答案 0 :(得分:2)

您需要URL-encode您的参数。考虑您正在使用的网址:

http://ec2-00-000-000-000.compute-1.amazonaws.com/OsProxy/getpage.aspx?p=https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true

这被解析为:

http://ec2-00-000-000-000.compute-1.amazonaws.com/OsProxy/getpage.aspx?
    p=https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&
    sensor=true

也就是说,您将sensor参数传递给amazonws.com,而不是googleapis.com

由于amazonws.com的唯一参数应该是完整的网址,因此请对该网址进行编码,使其达到amazonws.com作为单个参数传递给googleapis.com

http://ec2-00-000-000-000.compute-1.amazonaws.com/OsProxy/getpage.aspx?p=https%3A%2F%2Fmaps.googleapis.com%2Fmaps%2Fapi%2Fgeocode%2Fjson%3Faddress%3D1600%2BAmphitheatre%2BParkway%2C%2BMountain%2BView%2C%2BCA%26sensor%3Dtrue
相关问题