Requests POI from a location using Xamarin (Androi

2019-08-15 00:42发布

问题:

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...