The topic describes how to access the Bing Maps Web Services.
In order to use the Bing Maps Web Services, you must do the following:
- Get a key or token for use in your Bing Maps Web Services application.
- Use the Bing Maps Account Center to create a Bing Maps Developer Account as described in the Create a Bing Maps Developer Account section below. This allows you to get a Bing Maps Key for use in your application. Details about using the Bing Maps Account Center to get a key is in the Get a Bing Maps Key section below.
- If you require transaction reporting, use the Bing Maps Token Service to get a token for use in your application. This is described in the Requesting a Bing Maps Token topic.
- If you are using Visual Studio, add a service reference to one or more Bing Maps Web Services that provide the features you need. See the Generating Client Proxy Classes topic and the Bing Maps Web Services Metadata topic.
- In every Bing Maps Web Services request object, set the corresponding Credentials property to an object that contains a valid key or token.
- If you have used the Bing Maps Account Center to get a Bing Maps Key as described in the sections below, set the Credentials.ApplicationId Property to the key before using a service method to make a request. More information is in the Use the Bing Maps Key in Your Application section below.
- If you have used the Bing Maps Token Service, set the Credentials.Token Property to a retrieved token before using a service method to make a request. Note that tokens expire and so new tokens need to be retrieved on a regular basis.
Create a
Bing Maps Developer Account
To get a Bing Maps Key to use in your application, you need to create a Bing Maps Developer Account. A Bing Maps Key is automatically generated when you create an account.
Note: |
|---|
| After your account and first key are created, you can create up to four additional keys by clicking on the Create or view Bing Maps keys link. |
- Go to the Bing Maps Account Center at https://www.bingmapsportal.com and click the Create a Bing Maps account link.
- Sign in using your Windows Live ID. If you do not have a Windows Live ID, you can get one at https://www.bingmapsportal.com/SignIn/Logon.
- Once you have signed in using a valid Windows Live ID, you are asked to provide the following items:
- Account name Required. A friendly name that you and Microsoft can use to identify your account. You can also reference the unique ID that is assigned when your account is created.
- Contact name The name of the developer account owner. Alternatively, this is the name of someone that can be contacted when questions about this developer account arise.
- Company name The name of the company using this developer account.
- Email address Required. An email address which should be used to communicate with the developer account owner. This address can be the Windows Live ID used to login to the Bing Maps Account Center.
- Phone number A phone number that can be used in communications about this developer account.
- Application Name Required. The name of the application that will use the Bing Maps key that is automatically generated when your account is created.
- Application URL Required. The URL of the application that will use the Bing Maps key that is automatically generated when your account is created.
- Bing Maps API terms of use Required. Review the terms of use and check the box to accept them.
Tip: |
|---|
| You can update your Bing Maps Developer Account information any time by clicking the Update or view account details link. |
Once you have created a Bing Maps Developer Account and received your first key, you can create up to four additional Bing Maps Keys for use in your Bing Maps applications.
- On the Bing Maps Account Center left-hand navigation pane, click Create or view keys.
- To create a new key, enter the name of your application and the URL which corresponds to the website where the key will be used. Then click the Create key button. The page is updated and the new key is added to the list of available keys.
Important: |
|---|
| You can have up to five Bing Maps Keys. |
Use the
Bing Maps Key in Your Application
After you have created a Bing Maps Developer Account, available Bing Maps Keys appear in the Bing Maps Account Center. Click the Create or view Bing Maps keys link to view them. Copy the key associated with the Web site URL which corresponds to the application you are building and assign this string value to the ApplicationId property of a Credentials object. Use this object to set the Credentials property of the RequestBase Class.
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;
}
}
Transactions are counted for each Bing Maps Web Services request sent with a valid Bing Maps Key. The following list describes Bing Maps Web Services transactions.
Bing Maps Web Services: Geocode – Any time a request is made using the Geocode method, one transaction is counted.
Bing Maps Web Services: ReverseGeocode - Any time a request is made using the ReverseGeocode method, one transaction is counted.
Bing Maps: GetImageryMetadata – Any time a request is made using the GetImageryMetadata method, one transaction is counted.
Bing Maps Web Services: GetMapUri - Any time a request is made using the GetMapUri method, one transaction is counted.
Bing Maps Web Services: CalculateRoute – Any time a request is made using the CalculateRoute method, one transaction is counted.
Bing Maps Web Services: CalculateRoutesFromMajorRoads – If you make a request using the CalculateRoutesFromMajorRoads method and the MajorRoutesOptions.ReturnRoutes Property is set to false, one transaction is counted. If you make a request using the CalculateRoutesFromMajorRoads method and the MajorRoutesOptions.ReturnRoutes Property is set to true, one transaction plus one transaction per returned route is counted.
Bing Maps Web Services: Search - Any time a request is made using the Search method, one transaction is counted.