如何从街道地址获取坐标 [英] how to get coordinates from street address
问题描述
我正在使用 Windows Phone 8 应用程序,但找不到如何获取坐标表单地址.问题是,我有我的坐标,我需要计算我和某个地址之间的距离.
I'm working on windows phone 8 app, but i can't find, how to get coordinates form address. Problem is, i have my coordiantes, and i need to calculate distance between me and some address.
windows phone 8 没有那么多文档,所以请帮帮我.
windows phone 8 is not documented that much, so please help me.
推荐答案
您要查找的内容称为地理编码":将地址转换为地理坐标.
What you're looking for is called "geocoding": Converting an address to GeoCoordinate.
正如之前提到的,您可以在 WP7 上使用 Google 和 Bing 来实现这一目标.在 windows phone 8 上,作为框架的一部分支持地理编码和反向地理编码.您可以在这篇诺基亚介绍文章中阅读地理编码概述在地理编码"下)和更全面的概述 在另一篇诺基亚文章中.
As was mentioned before you can use Google and Bing on WP7 to achieve that. On windows phone 8 Geocoding and Reverse Geocoding are supported as part of the framework. You can read an overview to GeoCoding at this Nokia intro article (under "Geocoding") and a more comprehensive overview at this other Nokia article.
以下是将地址转换为坐标的地理编码示例:
Here's an example of Geocoding converting from an address to coordinates:
private void Maps_GeoCoding(object sender, RoutedEventArgs e)
{
GeocodeQuery query = new GeocodeQuery()
{
GeoCoordinate = new GeoCoordinate(0, 0),
SearchTerm = "Ferry Building, San-Francisco"
};
query.QueryCompleted += query_QueryCompleted;
query.QueryAsync();
}
void query_QueryCompleted(object sender, QueryCompletedEventArgs<IList<MapLocation>> e)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("Ferry Building Geocoding results...");
foreach (var item in e.Result)
{
sb.AppendLine(item.GeoCoordinate.ToString());
sb.AppendLine(item.Information.Name);
sb.AppendLine(item.Information.Description);
sb.AppendLine(item.Information.Address.BuildingFloor);
sb.AppendLine(item.Information.Address.BuildingName);
sb.AppendLine(item.Information.Address.BuildingRoom);
sb.AppendLine(item.Information.Address.BuildingZone);
sb.AppendLine(item.Information.Address.City);
sb.AppendLine(item.Information.Address.Continent);
sb.AppendLine(item.Information.Address.Country);
sb.AppendLine(item.Information.Address.CountryCode);
sb.AppendLine(item.Information.Address.County);
sb.AppendLine(item.Information.Address.District);
sb.AppendLine(item.Information.Address.HouseNumber);
sb.AppendLine(item.Information.Address.Neighborhood);
sb.AppendLine(item.Information.Address.PostalCode);
sb.AppendLine(item.Information.Address.Province);
sb.AppendLine(item.Information.Address.State);
sb.AppendLine(item.Information.Address.StateCode);
sb.AppendLine(item.Information.Address.Street);
sb.AppendLine(item.Information.Address.Township);
}
MessageBox.Show(sb.ToString());
}
当我在 WP8 上运行此代码片段时,我收到以下消息框:
When I run this code snippet on my WP8 I get the following messagebox:
这篇关于如何从街道地址获取坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!