locked
Google Maps integration RRS feed

  • Question

  • I am attempting to integrate Google Maps with an entity in CRM 2011 to improve my development skills.  I am running into a couple issue after following some of the examples I have found online.  I have kept it as simple as possible to get it working and will add to it.

    Here is my Web Resource for the IFrame:

    <html>
    <head>
        <title>Map</title>
        <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.17&libraries=geometry"></script>
        <script type="text/javascript" src="../WebResources/new_GoogleMaps.js"></script>
    </head>
    <body onload="InitializeMap()">
        <div id="map_canvas" style="width: 100%; height: 390px;"></div>
    </body>
    </html>

    Here is my JScript file:

    function InitializeMap(new_Lat, new_Long) {
                var map = null;

                var new_lat = Xrm.Page.getAttribute("new_lat").getValue();
                //var lattitude = parseFloat(latString);

                var new_long = Xrm.Page.getAttribute("new_long").getValue();
                //var longtitude = parseFloat(longString);

                var latlng = new google.maps.LatLng(new_lat, new_long);
                var myOptions = {
                                             zoom: 15,
                                             center: latlng,
                                             scaleControl: true,
                                             mapTypeId: google.maps.MapTypeId.ROADMAP
                };
        map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
        //var customMarker = new google.maps.Marker({
        //      google.maps.LatLng(44.9969338,-93.3746069),
        //      map: map
    //});
    }

    And I have added the 2 fields to be passed to the function:

    The problem I seem to be having is that the variables are undefined when I debug.

    It is almost like there is a disconnect between the Web Resource for the IFrame and the other fields on the form for this entity.  One article I read indicated that this was how you pass the fields from the form into the function.  But the Xrm reference doesn't work.  So I'm assuming there is another way to get the data into the function.

    If I hard code the latitude and longitude instead of passing them in, it works.  But I also see an error that pops up saying that Google is undefined.

    Any help or pointers will be appreciated.

    Jason Peterson


    Jason Peterson

    Wednesday, March 11, 2015 1:22 PM

Answers

  • Hello Jason,

    In case your webresource is embedded to CRM Form you would not be able to get field values using approach you've used. Try following:

    var new_lat = window.parent.Xrm.Page.getAttribute("new_lat").getValue();

    or

    var Xrm = window.parent.Xrm;
    var new_lat = Xrm.Page.getAttribute("new_lat").getValue();

    Also I hope my last article could be helpful for you - http://a33ik.blogspot.com/2015/03/howto-htmljs-webresources.html


    Dynamics CRM MVP
    My blog

    Wednesday, March 11, 2015 1:32 PM
    Moderator

All replies

  • Hello Jason,

    In case your webresource is embedded to CRM Form you would not be able to get field values using approach you've used. Try following:

    var new_lat = window.parent.Xrm.Page.getAttribute("new_lat").getValue();

    or

    var Xrm = window.parent.Xrm;
    var new_lat = Xrm.Page.getAttribute("new_lat").getValue();

    Also I hope my last article could be helpful for you - http://a33ik.blogspot.com/2015/03/howto-htmljs-webresources.html


    Dynamics CRM MVP
    My blog

    Wednesday, March 11, 2015 1:32 PM
    Moderator
  • Thanks Andrii.  I used the first one and it worked.

    Jason Peterson


    Jason Peterson

    Wednesday, March 11, 2015 2:54 PM