1

Windows Phone 8 の Maps API を使用して、現在の場所から (Foursquare や Google マップに似た) 場所の名前を取得したいと考えています。このチュートリアルのコードを使用して、現在の場所を既に取得できます。

誰でも私を助けることができますか?

4

2 に答える 2

2

ReverseGeocodeQueryクラスを使用できます。

var rgc = new ReverseGeocodeQuery();
rgc.QueryCompleted += rgc_QueryCompleted;
rgc.GeoCoordinate = myGeoCoord; //or create new gc with your current lat/lon info 
rgc.QueryAsync();

次に、渡されたイベント引数のResultプロパティをrgc_QueryCompleted使用して、イベント ハンドラー内からデータを取得できます。

于 2013-07-07T13:46:26.190 に答える
1

@keyboardP の回答では不十分な場合は、(うまくいけば) 場所に関する情報を取得するための実際の例を次に示します。少なくとも API 側からでは、検索できる「名前」プロパティはありません。

public async Task<MapLocation> ReverseGeocodeAsync(GeoCoordinate location)
{
    var query = new ReverseGeocodeQuery { GeoCoordinate = location };

    if (!query.IsBusy)
    {
        var mapLocations = await query.ExecuteAsync();
        return mapLocations.FirstOrDefault();
    }
    return null;
}

これを機能させるには、非同期クエリ用の次の拡張メソッドを追加する必要があります ( compiledexperience.com ブログから)

public static class GeoQueryExtensions
{
    public static Task<T> ExecuteAsync<T>(this Query<T> query)
    {
        var taskSource = new TaskCompletionSource<T>();

        EventHandler<QueryCompletedEventArgs<T>> handler = null;

        handler = (sender, args) =>
        {
            query.QueryCompleted -= handler;

            if (args.Cancelled)
                taskSource.SetCanceled();
            else if (args.Error != null)
                taskSource.SetException(args.Error);
            else
                taskSource.SetResult(args.Result);
        };

        query.QueryCompleted += handler;
        query.QueryAsync();

        return taskSource.Task;
    }
}
于 2014-02-21T13:01:19.757 に答える