how to get coordinates from street address

风流意气都作罢 提交于 2019-11-30 16:11:08

问题


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 is not documented that much, so please help me.


回答1:


What you're looking for is called "geocoding": Converting an address to GeoCoordinate.

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

When I run this code snippet on my WP8 I get the following messagebox:




回答2:


You have several options, the one i have use to accomplish this is using a web service, GOOGLE, BING, YAHOO ect.

on Bing (Cus is for windows phone) you need a key to access the maps api You can get the key at http://www.microsoft.com/maps/developers/mobile.aspx

once you have the key you can accese the WP7.1 SDK for BING or if that dont work for you, use the location api on the Rest Service http://msdn.microsoft.com/en-us/library/ff701715.aspx




回答3:


Bing Maps REST services also provides functionality to get Lat/Long from a given address, more info can be found on the MSDN here

You will need to get a Bind Maps key though here...



来源:https://stackoverflow.com/questions/14457247/how-to-get-coordinates-from-street-address

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!