C# iterate over MapLocationFinderResult

本文关键字:MapLocationFinderResult over iterate | 更新日期: 2023-09-27 18:16:12

我在试图从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"转换。MapsApp C:'Users'Robert'OneDrive'VSProjects'MapsApp'MapsApp' mapsapp' mainpage . example .cs 72 Active

我应该试着用某种方式来转换它吗?

这是在使用Windows.Services.Maps;Windows.Devices.Geolocation;Windows.UI.Xaml.Controls.Maps

C# iterate over MapLocationFinderResult

i的类型为MapLocation,但您试图将其用作索引。试试下面的代码:

foreach (MapLocation i in result.Locations)
{
    txtMessage.Text += (i.Address.Street + " 'n"); 
}
相关文章:
  • 没有找到相关文章