1

bing マップに問題があります。

最初のものは、My Location をクリックしたときに発生します。ほぼすべての場所で正常に動作していましたが、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
    };
}

何が問題ですか?修正方法は?

2 番目の質問は住所に関するものです。Address オブジェクトを取得すると、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が返されることだと思いました。しかし、正しいアドレスを送信するにはどうすればよいですか? FormattedAddress は良いですか?

ここに 2 つのGeoCodeAsyncandReverseGeocodeAsync関数があります。

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