Search code examples
c#navigationmapswindows-phone-8.1drive

Call Navigation/Maps/Drive with an Address in WP8.1 Application


I was wondering if it's possible to call the default navigation application within my Windows Phone 8.1 application. I have an address and I would like for the user to press a button and be able to navigate to that address through the default navigation app. If this is possible, how do I do it?

Thanks for your time,

Johan


Solution

  • You can launch turn-by-turn directions apps using the ms-drive-to and ms-walk-to schemes (depending on the type of directions you want) but you first need to get a geocoordinate for the address that you have. Since you're targeting Windows Phone 8.1, you can use the MapLocationFinder class in the Windows.Services.Maps namespace.

    string locationName = "Empire State Building";
    string address = "350 5th Avenue, New York City, New York 10018";
    
    var locFinderResult = await MapLocationFinder.FindLocationsAsync(
        address, new Geopoint(new BasicGeoposition()));
    
    // add error checking here
    
    var geoPos = locFinderResult.Locations[0].Point.Position;
    
    var driveToUri = new Uri(String.Format(
         "ms-drive-to:?destination.latitude={0}&destination.longitude={1}&destination.name={2}", 
         geoPos.Latitude, 
         geoPos.Longitude, 
         locationName));
    
    Launcher.LaunchUriAsync(driveToUri);