1

我的必应地图有一些问题。

第一个发生在我单击“我的位置”时 - 从几乎所有位置我都可以正常工作,但是有些位置返回 null,为什么?(它发生在我还没有地址的新建筑物中,也发生在没有互联网连接的建筑物中)。

方法:

private async void MyLocation_Click(object sender, RoutedEventArgs e)
{
    Bing.Maps.Location location = await GeoLocation.GetCurrentLocationAsync();

    MapLayer.SetPosition(_flagPin, location);
    map.SetView(location, 15);
}

第一行调用我的静态函数:

public static async Task<Bing.Maps.Location> GetCurrentLocationAsync()
{
    Geolocator geo = new Geolocator();
    geo.DesiredAccuracy = PositionAccuracy.Default;

    Geoposition currentPosition = null;
    currentPosition = await geo.GetGeopositionAsync();

    return new Bing.Maps.Location()
    {
        Latitude = currentPosition.Coordinate.Latitude,
        Longitude = currentPosition.Coordinate.Longitude
    };
}

问题是什么?如何解决?

第二个问题是关于地址的。当我得到一个地址对象时,我可以选择多种格式,例如 FormattedAddress、CountryRegion、PostalTown,我选择了 FormattedAddress,但它存在问题。

我的代码:

GeocodeResponse GP = await GeoLocation.ReverseGeocodeAsync(location.Latitude, location.Longitude);
EventContext.Address = GP.Results[0].Address.FormattedAddress;

问题是当我想发送地址并获取位置时。有时这段代码返回 null,为什么?

GeocodeResponse GP = await GeoLocation.GeocodeAsync(EventContext.Address);

我认为问题可能是有时地址(格式化)不好,有时它会给出奇怪的地址,例如“Street, st. Canada”,但找不到,因此它返回 null。但是我该怎么做才能发送正确的地址?FomattedAddress 好吗?

这是两个GeoCodeAsyncReverseGeocodeAsync功能:

public static async Task<GeocodeResponse> GeocodeAsync(string address)
{
    GeocodeService.GeocodeRequest geocodeRequest = new GeocodeService.GeocodeRequest();
    // Set credentials using a Bing Maps key
    geocodeRequest.Credentials = new GeocodeService.Credentials();
    geocodeRequest.Credentials.ApplicationId = Application.Current.Resources["BingCredentials"] as string;

    // Set the address
    geocodeRequest.Query = address;

    // Make the geocode request
    GeocodeService.GeocodeServiceClient geocodeService = new GeocodeServiceClient(GeocodeServiceClient.EndpointConfiguration.BasicHttpBinding_IGeocodeService);
    GeocodeResponse geocodeResponse = await geocodeService.GeocodeAsync(geocodeRequest);

    return geocodeResponse;
}

public static async Task<GeocodeResponse> ReverseGeocodeAsync(double latitude, double longitude)
{
    ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest();

    // Set credentials using a Bing Maps key
    reverseGeocodeRequest.Credentials = new GeocodeService.Credentials();
    reverseGeocodeRequest.Credentials.ApplicationId = Application.Current.Resources["BingCredentials"] as string;

    // Set the coordinates
    reverseGeocodeRequest.Location = new GeocodeService.GeocodeLocation() { Latitude = latitude, Longitude = longitude };

    // Make the reverse geocode request
    GeocodeServiceClient geocodeService = new GeocodeServiceClient(GeocodeServiceClient.EndpointConfiguration.BasicHttpBinding_IGeocodeService);
    GeocodeResponse geocodeResponse = await geocodeService.ReverseGeocodeAsync(reverseGeocodeRequest);

    return geocodeResponse;
}
4

1 回答 1

1

To clarify your first issue, are you getting null from the GPS or is it the address information in the result that is null the issue? If the GPS is returning null then it's possible that your GPS isn't able to get the current position where you are. This has nothing to do with Bing Maps and more so just an issue which your mobile device getting a clear view to the GPS satellites. If the issue is that the address information in the result is null then this is to be expected with new buildings that might not yet be known in the Bing Maps data set. It usually takes several months for new buildings to be found and added to the map data set. If you have no internet connection then the mobile device won't be able to connect to Bing Maps to get the address information. Note that Bing Maps is over 9 Petabytes in size so there is no local copy of the data on your mobile device.

If you already have the coordinates and the address information you shouldn't be geocoding it again. This is a waste of time and will cause issues. The geocoder will sometimes return "street" or "ramp" if the coordinate in which you pass to the reverse geocoder is on an unnamed street. Note geocoders are not designed to clean/validate addresses. They are designed to take an address and return a coordinate. Reverse geocoders are designed to take a coordinate and find the nearest address. Mixing the results from one with the other can result in odd results as the coordinates for each could be significantly different. It rare cases it's possible to loop between both services and get different results each time as the results will slightly be different and end up "walking" along a street.

于 2013-08-29T12:54:17.290 回答