Getting started overview

Integrating Bing Maps services requires a three-step process: account creation, API key generation, and making an authenticated request. This guide focuses on the Bing Maps REST Services, which provide programmatic access to geocoding, routing, and spatial data without requiring a full SDK integration for initial testing. The process applies to various Bing Maps offerings, including the Bing Maps V8 Web Control and Bing Maps SDKs for mobile platforms.

Before proceeding, ensure you have a Microsoft account. This account is essential for accessing the Bing Maps Dev Center, where API keys are managed. The free tier allows up to 50,000 transactions per month for non-commercial use, which is sufficient for initial development and testing before considering Bing Maps licensing options.

Here's a quick reference for the essential steps:

Step What to do Where
1. Create Account Sign up for a Microsoft account (if you don't have one). Microsoft account creation page
2. Access Dev Center Go to the Bing Maps Dev Center. Bing Maps Dev Center
3. Generate Key Create a new API key within your Dev Center dashboard. My Keys > Create a new key
4. Make Request Construct an API call using your generated key. Your preferred HTTP client or programming language

Create an account and get keys

To begin, you need a Microsoft account. If you already use services like Outlook.com, Xbox, or OneDrive, you likely have one. Otherwise, you can create a new Microsoft account. Once you have an account, navigate to the Bing Maps Dev Center and sign in.

Within the Dev Center, follow these steps to generate your API key:

  1. On the left-hand navigation pane, select My Keys.
  2. Click the Create a new key button.
  3. Fill in the required fields in the creation form:
    • Application name: Provide a descriptive name for your application (e.g., "My First Bing Maps App").
    • Application URL: If applicable, enter the URL where your application will be hosted (e.g., http://localhost:3000 for local development or your domain). For server-side requests, this field might be less critical but is good practice to include.
    • Key type: Select either Basic (suitable for most web and mobile applications) or Enterprise (for specific enterprise agreements). For initial development, Basic is typically sufficient.
    • Referer URL: For web applications, this field helps restrict key usage to specific domains. For initial testing with server-side requests, you might leave it blank or use * for broader access during development, but always configure specific referer URLs for production environments to enhance security, as outlined in the Bing Maps Dev Center FAQ.
  4. Click Create.

Your new API key will be displayed. This alphanumeric string is your credential for authenticating requests to Bing Maps services. Treat it like a password and do not expose it in client-side code for production applications unless specifically designed for web client use with appropriate referer restrictions. For server-side APIs, keep your key secure on your server.

Your first request

Let's make a simple geocoding request to convert a physical address into geographic coordinates (latitude and longitude). This is a common starting point for many mapping applications. We'll use the Bing Maps REST Services Locations API for this example.

API Endpoint:

GET https://dev.virtualearth.net/REST/v1/Locations?query={query}&key={BingMapsKey}

Parameters:

  • query: The address or place to geocode (e.g., "1 Microsoft Way, Redmond, WA").
  • key: Your Bing Maps API key.

Example using curl:

curl "https://dev.virtualearth.net/REST/v1/Locations?query=1%20Microsoft%20Way,%20Redmond,%20WA&key=YOUR_BING_MAPS_KEY"

Replace YOUR_BING_MAPS_KEY with the key you generated in the Dev Center. The %20 in the query parameter represents a space, which is standard URL encoding.

Expected JSON Response Structure:

{
  "authenticationResultCode": "ValidCredentials",
  "statusCode": 200,
  "statusDescription": "OK",
  "traceId": "...",
  "resourceSets": [
    {
      "estimatedTotal": 1,
      "resources": [
        {
          "__type": "Location:http://schemas.microsoft.com/search/local/ws/rest/v1",
          "bbox": [
            47.639686584472656,
            -122.13628387451172,
            47.64303970336914,
            -122.1265869140625
          ],
          "name": "1 Microsoft Way, Redmond, WA 98052",
          "point": {
            "coordinates": [
              47.641363,
              -122.131454
            ],
            "type": "Point"
          },
          "address": {
            "addressLine": "1 Microsoft Way",
            "adminDistrict": "WA",
            "adminDistrict2": "King Co.",
            "countryRegion": "United States",
            "formattedAddress": "1 Microsoft Way, Redmond, WA 98052",
            "locality": "Redmond",
            "postalCode": "98052"
          },
          "confidence": "High",
          "entityType": "Address",
          "geocodePoints": [
            {
              "coordinates": [
                47.641363,
                -122.131454
              ],
              "calculationMethod": "Interpolation",
              "usageTypes": [
                "Display",
                "Route"
              ]
            }
          ],
          "matchCodes": [
            "Good"
          ]
        }
      ]
    }
  ]
}

The key piece of information in the response is within resourceSets[0].resources[0].point.coordinates, which provides the latitude and longitude. The address.formattedAddress field confirms the recognized address.

Common next steps

Once you've successfully made your first request, several common paths can enhance your application's functionality:

  1. Displaying Maps: For interactive maps in a web browser, integrate the Bing Maps V8 Web Control. This JavaScript library allows you to embed maps, add markers, draw shapes, and handle user interactions. This method is distinct from the REST API, requiring you to load the JavaScript library in your HTML.
  2. Routing and Directions: Utilize the Bing Maps Routes API to calculate directions between two or more points. This API supports various modes of transport (driving, walking, transit) and optimization options.
  3. Geocoding and Reverse Geocoding: Beyond basic address lookup, explore batch geocoding for processing multiple addresses or reverse geocoding to convert coordinates back into human-readable addresses using the Locations API for reverse geocoding.
  4. Spatial Data Services: For more advanced geospatial analysis, Bing Maps offers services like Elevation API and Imagery API for accessing satellite, aerial, and street-level imagery and data.
  5. Mobile SDKs: For native iOS or Android applications, consider using the Bing Maps SDK for iOS or Bing Maps SDK for Android for optimized performance and native UI integration.
  6. Security Best Practices: Review Bing Maps security best practices. This includes limiting API key usage by referring domains, IP addresses, or application bundles, and avoiding exposing keys unnecessarily on the client-side. Similar principles apply to other mapping providers, such as the Google Maps API key best practices.

Troubleshooting the first call

If your initial Bing Maps API request fails, consider these common troubleshooting steps:

  • InvalidCredentials (401 Unauthorized):
    • API Key: Double-check that you have copied the key precisely from the Bing Maps Dev Center. Even minor typos can invalidate it.
    • Key Status: Ensure your key is active and has not been suspended or deleted in the Dev Center.
    • Referer Restrictions: If you configured referer URL restrictions for your key, ensure the domain or IP address from which you are making the request matches the allowed list. For command-line curl requests, you might need to temporarily remove referer restrictions or use a wildcard (*) for testing, then tighten security for production.
  • Incorrect Endpoint or Parameters:
    • URL Structure: Verify that the base URL (https://dev.virtualearth.net/REST/v1/Locations) is correct.
    • Parameter Names: Ensure parameter names like query and key are spelled correctly and case-sensitive if required.
    • URL Encoding: Confirm that any special characters in your query parameter (like spaces, commas, or `#`) are correctly URL-encoded (e.g., space becomes %20).
  • Network Issues:
    • Connectivity: Confirm your device has an active internet connection.
    • Firewall/Proxy: If you are in a corporate network, a firewall or proxy might be blocking outbound API calls. Consult your network administrator.
  • Exceeded Usage Limits:
    • If you are using the free tier or a paid plan, check your usage in the Bing Maps Dev Center to ensure you haven't exceeded your transaction limits. Exceeding limits will result in error responses.
  • Reviewing the Response:
    • The API response itself often contains diagnostic information in fields like authenticationResultCode, statusCode, and statusDescription, which can provide clues about the error. Consult the Bing Maps status codes and error handling documentation for specific error meanings.