在Windows Phone 8中,当我点击地图中的任何位置时,我都会检索Latitude和Longitude以及特定的
本文关键字:Latitude 检索 Longitude 任何 Phone Windows 位置 地图 | 更新日期: 2023-09-27 17:58:46
我的windows-phone-8项目中有
XAML代码:
<Controls:Map x:Name="MyMap" Tap="MyMap_Tap"/>
当点击事件触发时,我可以在消息框中获得Long和Lat,就像这样
C#代码:
private void MyMap_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
GeoCoordinate location = MyMap.ConvertViewportPointToGeoCoordinate(e.GetPosition(MyMap));
MessageBox.Show("latitude :" + location.Latitude +", longitude : " + location.Longitude);
}
我还需要得到这个位置的名字,加上它是Long和Lat,所以我该怎么做呢。
感谢
您可以使用从坐标到地址的反向地理编码转换:
private void Maps_ReverseGeoCoding(object sender, RoutedEventArgs e)
{
ReverseGeocodeQuery query = new ReverseGeocodeQuery()
{
GeoCoordinate = new GeoCoordinate(YourLatitude, YourLongitude)
};
query.QueryCompleted += query_QueryCompleted;
query.QueryAsync();
}
void query_QueryCompleted(object sender, QueryCompletedEventArgs<IList<MapLocation>> e)
{
StringBuilder placeString = new StringBuilder();
foreach (var place in e.Result)
{
placeString.AppendLine(place.GeoCoordinate.ToString());
placeString.AppendLine(place.Information.Name);
placeString.AppendLine(place.Information.Description);
placeString.AppendLine(place.Information.Address.BuildingFloor);
placeString.AppendLine(place.Information.Address.BuildingName);
placeString.AppendLine(place.Information.Address.BuildingRoom);
placeString.AppendLine(place.Information.Address.BuildingZone);
placeString.AppendLine(place.Information.Address.City);
placeString.AppendLine(place.Information.Address.Continent);
placeString.AppendLine(place.Information.Address.Country);
placeString.AppendLine(place.Information.Address.CountryCode);
placeString.AppendLine(place.Information.Address.County);
placeString.AppendLine(place.Information.Address.District);
placeString.AppendLine(place.Information.Address.HouseNumber);
placeString.AppendLine(place.Information.Address.Neighborhood);
placeString.AppendLine(place.Information.Address.PostalCode);
placeString.AppendLine(place.Information.Address.Province);
placeString.AppendLine(place.Information.Address.State);
placeString.AppendLine(place.Information.Address.StateCode);
placeString.AppendLine(place.Information.Address.Street);
placeString.AppendLine(iplaceem.Information.Address.Township);
}
MessageBox.Show(placeString.ToString());
}