Microsoft Dynamics CRM 2013: Google Maps instead of Bing Maps

I’ve always liked Google Maps better than Bing Maps, but after loading some test data into our new CRM, I was not happy with Bing because it was not finding a surprisingly large number of addresses. I’m not sure if it was the addresses with apartment numbers i.e. 1/2 Example Street, or those addresses without a country listed, but ALL of our addresses and people are in Australia so we have no use for the Country field.

All that aside, I think Google Maps looks better, is more accurate and has a very useful feature in a CRM in street view.

I’m very new to CRM, but to use Google maps, simply create a HTML web resource with the code below and then insert that web resource onto your Account or Contact form. This code is adaptable in the obvious spots. Without an address it defaults to Australia with a zoom level of 4. It uses the address1_composite field and if you want to debug failed addresses, uncomment the alert. Enjoy. I did.

 


<html>
<head>
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script>
function initialize() {
var map_canvas = document.getElementById('map_canvas');
var map_options = {
center: new google.maps.LatLng(-26.4420246,133.281323),
zoom: 4,
mapTypeId: google.maps.MapTypeId.ROADMAP
}

var map = new google.maps.Map(map_canvas, map_options)
var geocoder = new google.maps.Geocoder();
var address = window.parent.Xrm.Page.data.entity.attributes.get('address1_composite').getValue();
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
map.setZoom(14);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
//alert("Geocode was not successful for the following reason: " + status);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>

</head>
<body>
<div style="width: 100%; height: 100%;" id="map_canvas"></div>
</body>
</html>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s