VEMap.SetClientToken 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.

Note

This method is deprecated and should no longer be used. Please use the VEMap.SetCredentials Method with your Bing Maps Key for authentication.

Sets a Bing Maps token for the VEMap object.

VEMap.SetClientToken(clientToken);

Parameters

Parameter Description

clientToken

A string representing the Bing Maps token.

Remarks

This method is deprecated and should no longer be used. Please use the VEMap.SetCredentials Method with your Bing Maps Key for authentication.

The SetClientToken method is used to help Bing Maps customers monitor their map control usage. By setting a token on the VEMap object, requests made to Bing Maps by the map control can be tracked. More information is found in the Tracking Your Bing Maps Usage topic.

Use the SetClientToken method to set a token before calling the VEMap.LoadMap Method to ensure all map control and tile requests are tracked.

If an invalid token is set, the VEMap.ontokenerror Event fires when the map control makes a request to Bing Maps.

If an expired token is set, the VEMap.ontokenexpire Event fires when the map control makes a request to Bing Maps.

Example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
   <head>
      <title>SetClientToken</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');

            map.AttachEvent("ontokenerror", MyHandleTokenError);
            map.AttachEvent("ontokenexpire", MyHandleTokenExpire);            
         }

         function SetToken()
         {
            map.SetClientToken(document.getElementById('txtToken').value);
            alert("Token is set: " + document.getElementById('txtToken').value);
         }

         function LoadMap()
         {
            map.LoadMap();

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

         function MyHandleTokenError()
         {
            alert("Token is invalid.");
         }

         function MyHandleTokenExpire()
         {
            alert("Token has expired.");
          
         }

         function MakeBirdseyeRequest()
         {
            map.SetMapStyle(VEMapStyle.Birdseye);
         }
      </script>
   </head>
   <body onload="GetMap();">
      <input type="text" name="txtToken" value="TokenGoesHere"/>
      <input type="button" value="SetClientToken" onclick="SetToken();"/><br>
      <input type="button" value="Load the map after a token is set." onclick="LoadMap()";/>
      <div id='myMap' style="position:relative; width:600px; height:400px;"></div>
   </body>
</html>

See Also

Reference

VEMap.ontokenerror Event
VEMap.ontokenexpire Event