VEMap.SetCredentials Method

You are not viewing the latest version of the AJAX control. Bing Maps AJAX V7 is the recommended JavaScript control for Bing Maps. If you need this documentation, it is available in as a CHM or PDF download.

Sets the credentials to use to authenticate map service requests.

Note

Use the SetCredentials method to set the Bing Maps Key that you obtained from the Bing Maps Account Center as described in the Getting Started with the Bing Maps AJAX Control topic. Information about Bing Maps usage reports is in Viewing Bing Maps Usage Reports.

VEMap.SetCredentials(credentials);

Parameters

Parameter Description

credentials

A string that is the Bing Maps Key to set.

Example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
   <head>
      <title>SetCredentials</title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

      <script type="text/javascript" src="https://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.3"></script>

      <script type="text/javascript">
         var map     = null;
         
         function GetMap()
         {
            map = new VEMap('myMap');

            var mykey = "Bing Maps Key";
            map.SetCredentials(mykey);

            // Attach the credentials events
            map.AttachEvent("oncredentialserror", MyHandleCredentialsError);
            map.AttachEvent("oncredentialsvalid", MyHandleCredentialsValid);   
           
            LoadMap();
         
         }


         function LoadMap()
         {
            map.LoadMap();

            var location = new VELatLong(47.65, -122.2);
            map.SetCenterAndZoom(location, 18);

         }

         function MyHandleCredentialsError()
         {
            alert("The credentials are invalid.");
         }

         function MyHandleCredentialsValid()
         {
            alert("The credentials are valid.");
          
         }


      </script>
   </head>
   <body onload="GetMap();">
      <div id='myMap' style="position:relative; width:600px; height:400px;"></div>
   </body>
</html>