1

我正在尝试编码一个可与 google maps API 一起使用的 url

string rootURL = "http://maps.googleapis.com/maps/api/geocode/json?";
                        string[][] parms = new string[][] { new string[] { "Address", "3806", "Sterling Road", "Downers Grove", "IL" }, new string[] { "sensor", "false" } };
                        rootURL += HttpUtility.UrlEncode(parms[]);

最终结果应如下所示: http ://maps.googleapis.com/maps/api/geocode/json?address=3806+Sterling+Road,+Downers+Grove,+IL&sensor=false

不知道我在执行什么错误。

4

1 回答 1

2

试试这个:

var firstPart = new string[] {"3806", "Sterling Road", "Downers Grove", "IL"};
var secondPart = string.Format("{0}={1}", "sensor","false");
var joinedFirstPart = string.Join(" ", firstPart);
//we want to encode only the parameters with white spaces
var encodedParams = HttpUtility.UrlEncode(joinedFirstPart);
var rootUrl = string.Format("http://maps.googleapis.com/maps/api/geocode/json?address={0}&{1}", encodedParams, secondPart);
于 2013-05-10T16:59:29.023 回答