How to convert address to coordinates on Windows Phone?

Asked

Viewed 896 times

1

I need to create a route on the Windows Phone map. The starting place is the location of the phone, which I capture by the classes Geolocator and Geoposition. The place of arrival is an already premeditated address, but will not be in coordinates (Example: "Avenida Recife, Pernambuco"). In order to enter it in the method to create the route, the address must be in coordinates and I cannot find a way to perform 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();
}
  • 1

    You can get the coordinates from another app like Google Maps. For example, if you search for Avenida Recife at GM you will find the following URL: https://www.google.com/maps/place/Avenida+Recife/@-8.1201743,-34.9202733,17z/data=! 3m1! 4b1! 4m2! 3m1! 1s0x7ab1e95eecb6f7b:0x9b1d8bb39ab28ea3. Values -8.1201743,-34.9202733 are latitude and longitude.

  • If the user is going to do a textual search by destination on the phone itself, we can use some map component and read these coordinates from the component itself. http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207045(v=vs.105). aspx or http://developer.nokia.com/resources/library/Lumia/maps-and-navigation/guide-to-the-wp8-maps-api.html

  • Did you find a solution? Poste as an answer to help other people.

  • I think this link answers your question http://www.braincastexception.com/wp7-web-services-first-part-geocodeservice/

1 answer

1


It is possible to get the GPS coordinate from an address using the method Findlocationsasync.

Follow 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:

Nova Iguaçu: lat=-22.7528499998152 long=-43.5015199799091
Reef: lat=-8.11838996596634 long=-34.9464200343937

To learn more about using maps in Windows and Windows Phone apps, visit this tutorial at http://talkitbr.com/2015/06/12/desenvolvendo-mapas-em-universal-apps

Browser other questions tagged

You are not signed in. Login or sign up in order to post.