問題描述
將 Google Places API 與 MonoTouch 一起使用? (Using Google Places API with MonoTouch?)
I know it's possible to use the Google Places API with MonoTouch, but I'm having trouble getting it to work. I have the properly formated URL with my API key and all, but could someone please provide me with some example code of how to get and use the response from the request url? (ex: 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:
I ended up using the code below, it gives me a JsonArray of JsonObjects that I can iterate through and use. For this example it's for a places textsearch not a standard places search.
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
}