geocodeService.GeocodeCompleted += new EventHandler
The parameters are
- int id
- string color
- double heading
private void Geocode(string strAddress, int waypointIndex, int id, string color, double heading)
{
// Create the service variable and set the callback method using the GeocodeCompleted property.
GeocodeService.GeocodeServiceClient geocodeService = new GeocodeService.GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
// NEED TO PASS id, color, heading TO THIS EVENT HANDLER
geocodeService.GeocodeCompleted += new EventHandler
GeocodeService.GeocodeRequest geocodeRequest = new GeocodeService.GeocodeRequest();
geocodeRequest.Credentials = new Credentials();
geocodeRequest.Credentials.ApplicationId = ((ApplicationIdCredentialsProvider)BingMap.CredentialsProvider).ApplicationId;
geocodeRequest.Query = strAddress;
geocodeService.GeocodeAsync(geocodeRequest, waypointIndex);
}
private void geocodeService_GeocodeCompleted(object sender, GeocodeService.GeocodeCompletedEventArgs e)
{
GeocodeResult result = null;
if (e.Result.Results.Count > 0)
{
result = e.Result.Results[0];
if (result != null)
{
// this.ShowMarker(result);
this.ShowShip(result);
}
}
}
VulpesPosted Feb 2, 2013, 1:15 PM
This is because, to do this, you'd need to be able to change the type of the underlying delegate and the method which fires the event.
However, what you can do is to make the 3 extra parameters into fields of the class in which the eventhandler is defined so that the code in that handler will have access to their current values:
// add these fields
private int id;
private string color;
private double heading;
private void Geocode(string strAddress, int waypointIndex, int id, string color, double heading)
{
// Create the service variable and set the callback method using the GeocodeCompleted property.
GeocodeService.GeocodeServiceClient geocodeService = new GeocodeService.GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
// NEED TO PASS id, color, heading TO THIS EVENT HANDLER
geocodeService.GeocodeCompleted += new EventHandler
this.id = id;
this.color = color;
this.heading = heading;
GeocodeService.GeocodeRequest geocodeRequest = new GeocodeService.GeocodeRequest();
geocodeRequest.Credentials = new Credentials();
geocodeRequest.Credentials.ApplicationId = ((ApplicationIdCredentialsProvider)BingMap.CredentialsProvider).ApplicationId;
geocodeRequest.Query = strAddress;
geocodeService.GeocodeAsync(geocodeRequest, waypointIndex);
}
private void geocodeService_GeocodeCompleted(object sender, GeocodeService.GeocodeCompletedEventArgs e)
{
// this evenhandler now has access to the id, color and heading fields
GeocodeResult result = null;
if (e.Result.Results.Count > 0)
{
result = e.Result.Results[0];
if (result != null)
{
// this.ShowMarker(result);
this.ShowShip(result);
}
}
}