Invalid Credentials on MapLocationFinderResult uwp

2019-03-04 05:15发布

问题:

I am having a strange problem with the use of MapLocationFinder.

I am using MapLocationFinder to retrieve longitude and latitude based on string address:

string address = ""; // Any address here

var locFinderResult = await MapLocationFinder.FindLocationsAsync(address, new Geopoint(new BasicGeoposition()));

After this, I use Laucher to start "drive to" application and get navigation map:

var geoPos = locFinderResult.Locations[0].Point.Position;

var url = $"ms-drive-to:?destination.latitude={geoPos.Latitude.ToString(CultureInfo.InvariantCulture)}&destination.longitude={geoPos.Longitude.ToString(CultureInfo.InvariantCulture)}&destination.name={address}";
var driveToUri = new Uri(url);

await Launcher.LaunchUriAsync(driveToUri);

Up until recently this worked just fine on all devices. I was not required any token or anything, since I am not implementing Map control in XAML. However, a couple days ago I started receiving "InvalidCredentials" response for locFinderResult. It still works on only one device. I have never used any credentials so I don't know why it only works on this one.

Does anyone knows what could cause this issue?

回答1:

It looks like from some recent time Microsoft requires you to get the key from the Bing Maps Developers Center to use this functionality. See, the instructions: https://docs.microsoft.com/en-us/windows/uwp/maps-and-location/authentication-key



回答2:

Go to https://www.bingmapsportal.com and create a key. Then add it to your app.

MapService.ServiceToken = "MyKey";