Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WP8地图控件-使用等待函数获取城市名称_C#_Windows Phone 8_Asynchronous_Maps_Async Await - Fatal编程技术网

C# WP8地图控件-使用等待函数获取城市名称

C# WP8地图控件-使用等待函数获取城市名称,c#,windows-phone-8,asynchronous,maps,async-await,C#,Windows Phone 8,Asynchronous,Maps,Async Await,我有一个获取城市名称的函数: private async Task<string> OnMapHold() { ReverseGeocodeQuery query; List<MapLocation> mapLocations; MapLocation mapLocation; query = new ReverseGeocodeQuery(); query.GeoCoordinate = MyCoordinate; m

我有一个获取城市名称的函数:

private async Task<string> OnMapHold()
{
    ReverseGeocodeQuery query;
    List<MapLocation> mapLocations;
    MapLocation mapLocation;

    query = new ReverseGeocodeQuery();
    query.GeoCoordinate = MyCoordinate;

    mapLocations = (List<MapLocation>)await query.GetMapLocationsAsync();
    mapLocation = mapLocations.FirstOrDefault();

    if (mapLocation != null)
    {
        return mapLocation.Information.Address.City;
    }
    return "No City";
}
但是错误来了:在System.InvalidOperationException中发生了类型为“mscorlib.ni.dll”的异常。但我不知道该怎么办。我认为我的wait和async是错误的,但是我如何做才是正确的呢

编辑:


我现在使用这个示例,它对我有效。

GetMapLocationsAsync不是ReverseGeocodeQuery的一部分,你能为这个[extension]方法添加信息吗?好的,我使用这个示例:,现在它对我有效。
    string town = await OnMapHold(); // Error?