Use a Bing Map on a Dynamics CRM FOrm


/ Published in: HTML
Save to your folder(s)

Uses old Bing API


Copy this code and paste it in your HTML
  1. <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v = "urn:schemas-microsoft-com:vml">
  2.     <head>
  3.         <title>Fun With Bing Maps</title>
  4.         <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
  5.  
  6.         <script type="text/javascript" src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"></script>
  7.  
  8.         <script type="text/javascript" >
  9.             //Create a couple page level variables
  10.             var map = null;
  11.             var accountname = '';
  12.             function GetMap() {
  13.                 //Get the Account data from the Account Form
  14.                 var controls = parent.Xrm.Page.ui.controls;
  15.                 accountname = controls.get("name").getAttribute().getValue();
  16.                 var street1 = controls.get("address1_line1").getAttribute().getValue();
  17.                 var state = controls.get("address1_stateorprovince").getAttribute().getValue();
  18.                 var city = controls.get("address1_city").getAttribute().getValue();
  19.                 var postcode = controls.get("address1_postalcode").getAttribute().getValue();
  20.                 var country = controls.get("address1_country").getAttribute().getValue();
  21.                 //If we have the City field populated, let's try and get a map.  Otherwise, let's exit.
  22.                 if (city != null) {
  23.                     //Place into the map variable a NEW instance of the object VEMap and tie it to the myMap div section in our page body
  24.                     map = new VEMap('myMap');
  25.                     //Initialize the map
  26.                     map.LoadMap();
  27.                     var fulladdress = street1 + ', ' + city + ', ' + state + ', ' + postcode + ', ' + country;
  28.                     //Search for the address and create the map
  29.                     map.Find(accountname, fulladdress, VEFindType.Businesses, null, 0, 1, true, true, true, true, onfound);
  30.                 }
  31.                 else {
  32.                     //If you don't have a city populated, you're likely in the process of creating the record
  33.                     exit;
  34.                 }
  35.             }
  36.  
  37.             function onfound(layer, resultsArray, places, hasMore, veErrorMessage) {
  38.                 if (places) {
  39.                     //Create a PushPin object and place it at the Latitude/Longitude calculated from the map.Find
  40.                     var shape = new VEShape(VEShapeType.Pushpin, places[0].LatLong);
  41.                     //Give the PushPin a title
  42.                     shape.SetTitle(accountname);
  43.                     //Add the PushPin to the map
  44.                     map.AddShape(shape);
  45.                 }
  46.             }      
  47.           </script>
  48.           <link id="mapcontrolcss" rel="stylesheet" type="text/css" href="http://ecn.dev.virtualearth.net/mapcontrol/v6.3/css/bin/6.3.20091207154938.04/en/mapcontrol.css" rev="Stylesheet" />
  49.     </head>
  50.     <body onload="GetMap(); contentEditable=true">
  51.         <div style="position: relative; width: 100%; height: 100%" id="myMap"></div>
  52.     </body>
  53. </html>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.