Requests POI from a location using Xamarin (Android)

谁说胖子不能爱 提交于 2020-01-05 04:33:15

问题


Im trying to create an android app with xamarin.I want the user to be able to input an address/location and receive POI (Points of Interest) near it (within a certain radius).

I know google places api can do this, does xamarin have built in capability for something like this? Can I somehow interface with the Google Places api?

Or is there something I don't know about? Thanks for the help!


回答1:


Use HTTPWebRequest class to create a request to Google API, code snippet:

private void button1_Click(object sender, EventArgs e)
{
  HttpWebRequest webRequest = WebRequest.Create(@"https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=7500&types=library&sensor=false&key=AIzaSyD3jfeMZK1SWfRFDgMfxn_zrGRSjE7S8Vg") as HttpWebRequest;
  webRequest.Timeout = 20000;
  webRequest.Method = "GET";

  webRequest.BeginGetResponse(new AsyncCallback(RequestCompleted), webRequest);
}

private void RequestCompleted(IAsyncResult result)
{
  var request = (HttpWebRequest)result.AsyncState;
  var response = (HttpWebResponse)request.EndGetResponse(result);
  using (var stream = response.GetResponseStream())
  {
    var r = new StreamReader(stream);
    var resp = r.ReadToEnd();
  }
}

copy over from here... pretty straightforward and simple...



来源:https://stackoverflow.com/questions/29087675/requests-poi-from-a-location-using-xamarin-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!