在不知道纬度和经度的情况下,调用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()方法来获取地址的坐标。在实际应用中,你可能需要根据具体需求进行适当的错误处理和结果处理。
云原生正发声
小程序云开发官方直播课(应用开发实战)
技术创作101训练营
云+社区开发者大会 武汉站
云+社区技术沙龙[第14期]
云+社区开发者大会(苏州站)
Hello Serverless 来了
腾讯位置服务技术沙龙
小程序·云开发官方直播课(数据库方向)
领取专属 10元无门槛券
手把手带您无忧上云