在不知道纬度和经度的情况下,调用MapLocationFinder.FindLocationsAsync()来获取地址的坐标的方法如下:
以下是一个示例代码:
using Windows.Services.Maps;
using Windows.Devices.Geolocation;
public async void GetLocationFromAddress(string address)
{
Geopoint queryPoint = null;
MapLocationFinderResult result = await MapLocationFinder.FindLocationsAsync(address, queryPoint);
if (result.Status == MapLocationFinderStatus.Success && result.Locations.Count > 0)
{
MapLocation location = result.Locations[0];
Geopoint coordinates = location.Point;
// 获取到地址的坐标
double latitude = coordinates.Position.Latitude;
double longitude = coordinates.Position.Longitude;
// 在这里可以进行后续的操作,如显示在地图上或保存到数据库中
}
else
{
// 无法获取到地址的坐标,处理错误情况
}
}
请注意,以上示例代码仅展示了如何使用MapLocationFinder.FindLocationsAsync()方法来获取地址的坐标。在实际应用中,你可能需要根据具体需求进行适当的错误处理和结果处理。
领取专属 10元无门槛券
手把手带您无忧上云