ImageryServiceClient.GetMapUri Method

Retrieves a URI that can be used to access a static map image.

public MapUriResponse GetMapUri(MapUriRequest request)

Parameters

request
A MapUriRequest object that contains the header and parameter information for the service operation.

Return Value

Returns a MapUriResponse Class, which contains a URI to a static map image.

Example

C#

private void RequestImage()
{
    try
    {
        // Get a Bing Maps token before making a request
        string token = GetToken();
                        
        ImageryService.MapUriRequest mapUriRequest = new ImageryService.MapUriRequest();
        
        // Set credentials using a valid Bing Maps Token
        mapUriRequest.Credentials = new ImageryService.Credentials();
        mapUriRequest.Credentials.Token  = token;
        
        // 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;
        
    }

}


// The GetToken function needs to be called once before any web service request is made. Once
//    the token is retrieved, it can be cached for use in subsequent web service requests.

private string GetToken()
{
    // Set Bing Maps Developer Account credentials to access the Token Service
    TokenWebReference.CommonService commonService = new TokenWebReference.CommonService();
    commonService.Credentials = new System.Net.NetworkCredential("VEDevAccountID", "VEDevAccountPassword");
                
    // Set the token specification properties
    TokenWebReference.TokenSpecification tokenSpec = new TokenWebReference.TokenSpecification();
    tokenSpec.ClientIPAddress = "ClientIPAddress";
    tokenSpec.TokenValidityDurationMinutes = 60;

    string token = "";

    // Get a token
    try
    {
        token = commonService.GetClientToken(tokenSpec);
    }
    catch (Exception ex)
    {
        throw ex;
    }

    return token;
    
}
    
   
See Also

Reference

ImageryServiceClient.GetImageryMetadata Method

Concepts

Understanding Tiles

Page view tracker