【发布时间】:2020-12-12 16:34:24
【问题描述】:
我正在尝试修改代码 here 以获取传入地址的纬度和经度。
但是,传递给 MapLocationFinder.FindLocationsAsync() 的参数之一是已经设置了纬度和经度的 Geopoint,就像上面引用的代码中这样:
// The nearby location to use as a query hint.
BasicGeoposition queryHint = new BasicGeoposition();
queryHint.Latitude = 47.643;
queryHint.Longitude = -122.131;
Geopoint hintPoint = new Geopoint(queryHint);
// Geocode the specified address, using the specified reference point
// as a query hint. Return no more than 3 results.
MapLocationFinderResult result =
await MapLocationFinder.FindLocationsAsync(
addressToGeocode,
hintPoint,
3);
最终的结果就是设置了经纬度:
if (result.Status == MapLocationFinderStatus.Success)
{
tbOutputText.Text = "result = (" +
result.Locations[0].Point.Position.Latitude.ToString() + "," +
result.Locations[0].Point.Position.Longitude.ToString() + ")";
}
这对我来说没有意义 - 该方法的全部目的是设置纬度和经度,换句话说,在调用 MapLocationFinder.FindLocationsAsync() 时它们是未知的。
这是我的代码,我对上面和给定链接的内容进行了改编:
public sealed partial class MainPage : Page
{
. . .
// Global, set by call to SetLatAndLongForAddress()
double latitude = 0.0;
double longitude = 0.0;
. . .
private async void SetLatAndLongForAddress(string fullAddress)
{
try
{
string addressToGeocode = fullAddress;
MapLocationFinderResult mapLocFinderResult =
await MapLocationFinder.FindLocationsAsync(
addressToGeocode,
null,
1); // changed 3 to 1 - only want one returned val
if (mapLocFinderResult.Status == MapLocationFinderStatus.Success)
{
latitude = mapLocFinderResult.Locations[0].Point.Position.Latitude;
longitude = mapLocFinderResult.Locations[0].Point.Position.Longitude;
}
}
. . .
}
这是执行此操作的方法吗 - 将 null 而不是 Geopoint 作为第二个参数传递给 MapLocationFinder.FindLocationsAsync()?这会起作用吗,或者我对此有什么误解?
【问题讨论】:
标签: c# uwp bing-maps geopoints uwp-maps