我在尝试从MapLocationFinderResult列表中获取多个项目时感到困惑。 我尝试过使用foreach循环:
private async void GetRouteAndDirections()
{
// Query hint
queryHint = new BasicGeoposition();
queryHint.Latitude = -37.8136;
queryHint.Longitude = 144.9631;
Geopoint hintPoint = new Geopoint(queryHint);
// Start
//BasicGeoposition startLocation = new BasicGeoposition();
result = await MapLocationFinder.FindLocationsAsync(addressToGeocode, hintPoint, 10);
// End
// Get route
// Show
if (result.Status == MapLocationFinderStatus.Success)
{
foreach (MapLocation i in result.Locations)
{
txtMessage.Text += (result.Locations[i].Address.Street + " \n"); // need to figure out how to iterate over this
}
AddMapIcon();
}
错误是:
严重性代码描述项目文件行抑制状态 错误CS1503参数1:无法转换为' Windows.Services.Maps.MapLocation'到' int' MapsApp C:\ Users \ Robert \ OneDrive \ VSProjects \ MapsApp \ MapsApp \ MainPage.xaml.cs 72有效
我应该尝试投射吗?
这是使用Windows.Services.Maps; Windows.Devices.Geolocation; Windows.UI.Xaml.Controls.Maps
答案 0 :(得分:0)
i
的类型为MapLocation
,但您尝试将其用作索引。试试这段代码:
foreach (MapLocation i in result.Locations)
{
txtMessage.Text += (i.Address.Street + " \n");
}