Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kristoffer Sterndorff-Jessen 2 posts 32 karma points
    Feb 17, 2014 @ 14:57
    Kristoffer Sterndorff-Jessen
    0

    Google maps datatype not working

    Hello. I downloaded google maps datatype v. 2.1.0. I am using Umbraco version 6.0.6

    I am trying to display google maps, so I can put pins og retrieve locations from the map, but I cannot get any map to show :(

    I installed the Datatype and named it: Google Map. I can see it in the Developer section under Data types.

    I made a template and a javascript file.

    Template: myTemplate

    <div id="googleMap" class="contactMap"></div>

       
    <script type="text/javascript">
            $
    (document).ready(function () {
                $
    ("#googleMap").googleMap("<umbraco:Item field='gmap' runat='server'/>");
           
    });
       
    </script>

    Script googleMap: 

    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
        <script type="text/
    javascript">
            $
    .fn.googleMap = function (location, options) {
               
    var defaults = {
                    lat
    : 53.41,
                   
    long: -2.99,
                    zoom
    : 13,
                    mapTypeId
    : google.maps.MapTypeId.ROADMAP,
                    mapTypeControl
    : false,
                    controls
    : ['GSmallZoomControl3D']
               
    };

                options
    = $.extend(defaults, options || {});

               
    if (location) {
                   
    var value = $.trim(location);
                   
    var point = value.split(',');
                    options
    .lat = parseFloat(point[0]);
                    options
    .long = parseFloat(point[1]);
                    options
    .zoom = parseFloat(point[2]);
               
    };

               
    var center = new google.maps.LatLng(options.lat, options.long);

               
    var map = new google.maps.Map(this.get(0), $.extend(options, { center: center }));

               
    var storeMarker = new google.maps.Marker({
                    position
    : center,
                    map
    : map
               
    });
           
    };
       
    </script>

    But I receive nothing at all. Any suggestions

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Feb 17, 2014 @ 15:32
    Dennis Aaen
    100

    Hi Kristoffer,

    I just test your code on a fresh Umbraco 6.0.6, and I works just fine. You´re just missing a very small part. To get the map visible on the front you need to added a width and a height on the map container div, could be by css or just by adding the width and the height on the div by using the style attribut.

    The css way: inline in your head section:

    <style>
       
    #googleMap{
           height
    :500px;
           width
    :569px;
       
    }
    </style>

    Css by stylesheet:

    #googleMap{
    height: 500px;
       width: 569px;
    }

    Adding the width and height on div by using style attribute:

    <divid="googleMap"class="contactMap"style="width:569px; height:500px;"></div>

    /Dennis

  • Kristoffer Sterndorff-Jessen 2 posts 32 karma points
    Feb 18, 2014 @ 07:59
    Kristoffer Sterndorff-Jessen
    0

    Wow, you were right. Thanks a bunch. I am still a rookie in the html/css/javascript world :)

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Feb 18, 2014 @ 08:14
    Dennis Aaen
    0

    Hi Kristoffer,

    Great you got it working.

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft