how to get coordinates from street address

前端 未结 3 972
遥遥无期
遥遥无期 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> 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

提交回复
热议问题