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.

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.



Parameter Description


A string that is the Bing Maps Key to set.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

      <script type="text/javascript" src=""></script>

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

            var mykey = "Bing Maps Key";

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

         function 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.");

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