private void RequestImage()
{
try
{
// Set a Bing Maps key before making a request
string key = "Bing Maps Key";
ImageryService.MapUriRequest mapUriRequest = new ImageryService.MapUriRequest();
// Set credentials using a valid Bing Maps Key
mapUriRequest.Credentials = new ImageryService.Credentials();
mapUriRequest.Credentials.ApplicationId = key;
// Set the location of the requested image
mapUriRequest.Center = new ImageryService.Location();
mapUriRequest.Center.Latitude = 47.65;
mapUriRequest.Center.Longitude = -122.24;
// Set the map style and zoom level
ImageryService.MapUriOptions mapUriOptions = new ImageryService.MapUriOptions();
mapUriOptions.Style = ImageryService.MapStyle.AerialWithLabels;
mapUriOptions.ZoomLevel = 10;
// Set the size of the requested image to match the size of the image control
mapUriOptions.ImageSize = new ImageryService.SizeOfint();
mapUriOptions.ImageSize.Height = (int)Image1.Height.Value;
mapUriOptions.ImageSize.Width = (int)Image1.Width.Value;
mapUriRequest.Options = mapUriOptions;
ImageryService.ImageryServiceClient imageryService = new ImageryService.ImageryServiceClient();
// Make the image request
ImageryService.MapUriResponse mapUriResponse = imageryService.GetMapUri(mapUriRequest);
string mapUri = mapUriResponse.Uri;
// Set the image control URL to the returned image URI
Image1.ImageUrl = mapUri;
}
catch (Exception ex)
{
errorLabel.Text = "An exception occurred: " + ex.Message;
}
}