Can I get geocode by country and postal code? RRS feed

  • Question

  • Here is my code, when "address" is a full address like No. Road Name, Country Name, it works. If "address" just country name and postal code, it doesn't work.

    So, can I get geocode using bing map just passing country name and postalcode values?

    private void GeocodeAddress(string address)
            string key = "xxxxxxxxxxxxx";
            GeocodeRequest geocodeRequest = new GeocodeRequest();
            // Set the credentials using a valid Bing Maps keyf
            geocodeRequest.Credentials = new GeocodeService.Credentials();
            geocodeRequest.Credentials.ApplicationId = key;
            // Set the full address query
            geocodeRequest.Query = address;
            // Set the options to only return high confidence results 
            FilterBase[] filters = new FilterBase[1];
            filters[0] = new ConfidenceFilter() { MinimumConfidence = Confidence.High };
            GeocodeOptions geocodeOptions = new GeocodeOptions();
            geocodeOptions.Filters = new ObservableCollection<FilterBase>(filters);
            geocodeRequest.Options = geocodeOptions;
            // Make the geocode request
            GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
            geocodeService.GeocodeCompleted += new EventHandler<GeocodeCompletedEventArgs>(geocodeService_GeocodeCompleted);
        void geocodeService_GeocodeCompleted(object sender, GeocodeCompletedEventArgs e)
            // The result is a GeocodeResponse object
            GeocodeResponse geocodeResponse = e.Result;
            if (geocodeResponse.Results.Count > 0)
                _latitude = geocodeResponse.Results[0].Locations[0].Latitude;
                _longitude = geocodeResponse.Results[0].Locations[0].Longitude;

    Tuesday, June 19, 2012 2:25 AM