how to get coordinates from street address

前端 未结 3 990
遥遥无期
遥遥无期 2021-01-03 14:02

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

相关标签:
3条回答
  • 2021-01-03 14:32

    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:

    MEssageBox showing details for the ferry building

    0 讨论(0)
  • 2021-01-03 14:41

    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...

    0 讨论(0)
  • 2021-01-03 14:51

    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

    0 讨论(0)
提交回复
热议问题