我正在尝试使用google places API在窗口手机8地图控件上显示离我当前位置1公里内的地方。我正在使用JSON解析来获取纬度,经度和名称。现在,当用户点击任何地方圈时,我希望名称显示为工具提示。
//使用Google API显示POI
HttpClient client = new HttpClient();
string baseUrl = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=" + position.Coordinate.Latitude + "," + position.Coordinate.Longitude + "&radius=1000&keyword=hospital&key=AIzaSyBCccOYAea2ITvgqNpIHcutuExQwzQctCk";
string googleResult = await client.GetStringAsync(baseUrl);
//解析JSON数据
JObject obj = JObject.Parse(googleResult);
JArray jarr = (JArray)obj["results"];
foreach(var item in jarr)
{
string name = (string)item.SelectToken("name");
double lt = (double)item.SelectToken("geometry.location.lat");
double lg = (double)item.SelectToken("geometry.location.lng");
//Create a small circle to mark the current location.
Ellipse myCircle2 = new Ellipse();
myCircle2.Fill = new SolidColorBrush(Colors.Red);
myCircle2.Height = 10;
myCircle2.Width = 10;
myCircle2.Opacity = 50;
// Create a MapOverlay to contain the circle.
MapOverlay myLocationOverlay2 = new MapOverlay();
myLocationOverlay2.Content = myCircle2;
myLocationOverlay2.PositionOrigin = new Point(0.5, 0.5);
GeoCoordinate myGeoCoordinate2 = new GeoCoordinate(lt, lg);
myLocationOverlay2.GeoCoordinate = myGeoCoordinate2;
// Create a MapLayer to contain the MapOverlay.
MapLayer myLocationLayer2 = new MapLayer();
myLocationLayer2.Add(myLocationOverlay2);
// Add the MapLayer to the Map.
Bmap.Layers.Add(myLocationLayer2);
}