We help IT Professionals succeed at work.

Windows Phone 7 Bing Maps

I am attempting to write an app for Windows Phone 7 that connects to the Bing Maps Geocode service to provide latitude and longitude for a given zip code.  The code is attached.

On line 21 (the line that reads):

   GeocodeResponse geocodeResponse = geocodeService.GeocodeAsync(geocodeRequest);


I am getting an error that states:

"Cannot implicitly convert type 'void' to 'WeatherApp.GeocodeService.GeocodeResponse'"

The underlined section is the entire clause after the equal sign.

Any help would be much appreciated.
public string GeocodeAddress(string zipCode)
        {
            string results = "";
            string key = "MyBingMapsKey";
            GeocodeService.GeocodeRequest geocodeRequest = new GeocodeService.GeocodeRequest();

            geocodeRequest.Credentials = new GeocodeService.Credentials();
            geocodeRequest.Credentials.ApplicationId = key;

            geocodeRequest.Query = zipCode;

            ConfidenceFilter[] filters = new ConfidenceFilter[1];
            filters[0] = new ConfidenceFilter();
            filters[0].MinimumConfidence = GeocodeService.Confidence.High;

            GeocodeOptions geocodeOptions = new GeocodeOptions();
            geocodeOptions.Filters = filters;
            geocodeRequest.Options = geocodeOptions;

            GeocodeServiceClient geocodeService = new GeocodeServiceClient();
            GeocodeResponse geocodeResponse = geocodeService.GeocodeAsync(geocodeRequest);

            if (geocodeResponse.Results.Length > 0)
                results = String.Format("Latitude: {0}\nLongitude: {1}",
                  geocodeResponse.Results[0].Locations[0].Latitude,
                  geocodeResponse.Results[0].Locations[0].Longitude);
            else
                results = "No Results Found";

            return results;
        }

Open in new window

Comment
Watch Question

BRONZE EXPERT
Commented:
There is no return for the Async methods in wp7. You need to attach to the completed event and use the result args from there.
BRONZE EXPERT

Commented:
An example of using the Async methodology


geocodeService.ReverseGeocodeCompleted += new EventHandler<ReverseGeocodeCompletedEventArgs>(geocodeService_ReverseGeocodeCompleted);
geocodeService.ReverseGeocodeAsync(reverseGeocodeRequest);

void geocodeService_ReverseGeocodeCompleted(object sender, ReverseGeocodeCompletedEventArgs e)
{
       // The result is a GeocodeResponse object
       GeocodeResponse geocodeResponse = e.Result;

       if (geocodeResponse.Results.Length> 0)
    OutPutText.Text = geocodeResponse.Results[0].DisplayName;
else
    OutPutText.Text = "No Results found";
}

Author

Commented:
Many thanks!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.