将Google Places API与MonoTouch一起使用?

时间:2012-09-19 18:08:19

标签: ios google-maps xamarin.ios google-api monodevelop

我知道可以将Google Places API与MonoTouch一起使用,但我无法让它运行起来。我有一个正确格式化的URL和我的API密钥,但有人可以请我提供一些示例代码,说明如何获取和使用请求URL的响应? (例如:https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=AddYourOwnKeyHere

1 个答案:

答案 0 :(得分:0)

我最终使用下面的代码,它给了我一个JsonObject的JsonArray,我可以迭代并使用它。对于这个例子,它是一个地方文本搜索而不是标准的地方搜索。

HttpWebRequest url = (HttpWebRequest)WebRequest.Create("https://maps.googleapis.com/maps/api/place/textsearch/json?    query=Sushi&sensor=false&type=restaurant&key=YOUR_KEY_HERE");
HttpWebResponse temp = (HttpWebResponse)url.GetResponse ();
JsonValue jval = JsonObject.Load (temp.GetResponseStream ());
JsonObject jobj = (JsonObject)jval;
var resultJson = jobj["results"]; 
foreach (JsonObject jentry in resultJson)
{
//Do stuff with the jentry
}