0

ReverseGeocodeQuery 给出错误

1.in "GeoCoordinate(47.60887, -122.34094); "方法必须有返回类型

2.在“reverseGeocode.GeoCoordinate line”中,reverseGeocode 是一个字段,但它的使用就像一个类型..

ReverseGeocodeQuery reverseGeocode = new ReverseGeocodeQuery();
reverseGeocode.GeoCoordinate = new GeoCoordinate(47.60887, -122.34094);
reverseGeocode.QueryCompleted += reverseGeocode_QueryCompleted;
reverseGeocode.QueryAsync();
void reverseGeocode_QueryCompleted(objectsender,QueryCompletedEventArgs<IList<MapLocation>> e)
{
MapAddress geoAddress = e.Result[0].Information.Address;           
}

我使用了命名空间——使用 Microsoft.Phone.Maps.Services;

如何纠正这个错误..

4

1 回答 1

1

得到了答案

GeoCoordinateWatcher myLocationWatcher;
private GeoCoordinate MyCoordinate = null;
private async void GetCurrentCoordinate()
    {
        Geolocator geolocator = new Geolocator();
        geolocator.DesiredAccuracy = PositionAccuracy.High;

        try
        {
            Geoposition currentPosition = await geolocator.GetGeopositionAsync(TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(10));
            _accuracy = currentPosition.Coordinate.Accuracy;

            MyCoordinate = new GeoCoordinate(currentPosition.Coordinate.Latitude, currentPosition.Coordinate.Longitude);

            if (MyReverseGeocodeQuery == null || !MyReverseGeocodeQuery.IsBusy)
            {
                MyReverseGeocodeQuery = new ReverseGeocodeQuery();
                MyReverseGeocodeQuery.GeoCoordinate = new GeoCoordinate(MyCoordinate.Latitude, MyCoordinate.Longitude);
                LongitudeTextBlock.Text = MyCoordinate.Longitude.ToString();
                LatitudeTextBlock.Text = MyCoordinate.Latitude.ToString();
                MyReverseGeocodeQuery.QueryCompleted += ReverseGeocodeQuery_QueryCompleted;
                MyReverseGeocodeQuery.QueryAsync();
            }

        }
        catch (Exception ex)
        {
            // ...

        }

    }


    public void ReverseGeocodeQuery_QueryCompleted(object sender, QueryCompletedEventArgs<IList<MapLocation>> e)
    {
        if (e.Error == null)
        {
            if (e.Result.Count > 0)
            {
                MapAddress address = e.Result[0].Information.Address;
                labelResults.Text = "Current Location: " + address.City + ", " + address.State;
            }
        }
    }


    public void Button_Click(object sender, RoutedEventArgs e)
    {
        GetCurrentCoordinate();

    }
于 2013-08-19T15:47:38.460 回答