Skip to main content
 首页 » 编程设计

c#之使用 Xamarin (Android) 从某个位置请求 POI

2024年02月06日11落叶无声

我正在尝试使用 xamarin 创建一个 android 应用程序。我希望用户能够输入地址/位置并接收它附近(在一定半径内)的 POI(兴趣点)。

我知道 google places api 可以做到这一点,xamarin 是否内置了这样的功能?我能以某种方式与 Google Places api 交互吗?

还是有什么我不知道的?感谢您的帮助!

请您参考如下方法:

使用 HTTPWebRequest 类创建对 Google API 的请求,代码 fragment :

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(); 
  } 
} 

从here复制过来...非常简单明了...