How to convert address in coordinates in Windows Phone?

1

I need to create a route on the Windows Phone map. The place of departure is the location of the phone, which I capture through the Geolocator and Geoposition classes. The place of arrival is an address already premeditated, but will not be in coordinates (Example: "Avenida Recife, Pernambuco"). In order to insert it into the method for creating the route, the address must be in coordinates and I can not find a way to do this conversion.

Here's an example of how I'm doing this route:

async void ObterLocalizacaoAsync(double latitude, double longitude)
{
    Geolocator localizacao = new Geolocator();
    localizacao.DesiredAccuracy = PositionAccuracy.High;
    Geoposition posicao = await localizacao.GetGeopositionAsync();

    latitude = posicao.Coordinate.Latitude;
    longitude = posicao.Coordinate.Longitude;
}
void appRotaButton_Click(object sender, EventArgs e)
{ 
    ObterLocalizacaoAsync(latitude, longitude);
    MapsDirectionsTask rota = new MapsDirectionsTask();
    rota.Start = new LabeledMapLocation("Sua posição", new GeoCoordinate(latitude, longitude));
    rota.End = new LabeledMapLocation("Posição final", <coordenada-do-endereco>);
    rota.Show();
}
    
asked by anonymous 30.05.2014 / 03:37

1 answer

1

You can get the GPS coordinate from an address by using the FindLocationsAsync method.

Here's an example:

        Geolocator geolocator = new Geolocator();
        Geoposition geoposition = await geolocator.GetGeopositionAsync();

        // O valor 10 passado como parâmetro delimita o número máximo de resultados da busca
        MapLocationFinderResult result = await MapLocationFinder.FindLocationsAsync("Avenida Recife Pernambuco Brasil", new Geopoint(new BasicGeoposition()), 10);

        if (null != result)
        {
            List<MapLocation> locations = result.Locations.ToList();

            if (null != locations && locations.Count > 0)
            {
                System.Diagnostics.Debug.WriteLine(string.Format("Encontrado {0} resultados:", locations.Count));

                foreach (MapLocation location in locations)
                {
                    System.Diagnostics.Debug.WriteLine(string.Format("{0}: lat={1} long={2}", location.Address.Town, location.Point.Position.Latitude, location.Point.Position.Longitude));
                }
            }
        }

Found 2 results:

New : lat = - 22.7528499998152 long = - 43.5015199799091 < lat = - 8.11838996596634 long = - 34.9464200343937

To understand more about using maps in Windows and Windows Phone applications, visit this tutorial at link

    
12.06.2015 / 19:54