Copied to clipboard

Flag this post as spam?

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


  • Owain Williams 480 posts 1412 karma points MVP 6x c-trib
    Jul 16, 2015 @ 09:25
    Owain Williams
    0

    How to make this work in Umbraco 7?

    Hi, I have the map working on the backend which is great but how do I pull it through to a page on the frontend? I tried to follow the instructions in another thread but, I could be wrong, but it seemed to be for Umbraco 6?

    Any instructions would be great. Thanks.

  • Owain Williams 480 posts 1412 karma points MVP 6x c-trib
    Jul 16, 2015 @ 11:16
    Owain Williams
    100

    To help others, I have now got this to work.

    On my page template I have -

    @{
        var lat = CurrentPage.location.Latitude;
        var lng = CurrentPage.location.Longitude;
        var zoom = CurrentPage.location.Zoom;
        var latlng = lat+","+lng;
    }
    
    <!-- GOOGLE MAPS -->
    
            <style type="text/css">
          html, body, #map-canvas { height: 200px; margin: 0; padding: 0;}
        </style>
        <script type="text/javascript"
          src="https://maps.googleapis.com/maps/api/js?key=[YOUR-API-KEY]">
        </script>
        <script type="text/javascript">
          function initialize() {
            var myLatlng = new google.maps.LatLng(@latlng);
    
              var mapOptions = {
              center: { lat: @lat, lng: @lng},
              zoom: 11
            };
            var map = new google.maps.Map(document.getElementById('map-canvas'),
                mapOptions);
    
              var marker = new google.maps.Marker({
          position: myLatlng,
          map: map,
          title: 'Hello World!',
              animation: google.maps.Animation.DROP
    
      });
          }
          google.maps.event.addDomListener(window, 'load', initialize);
        </script>
    

    The section above the GOOGLE MAP comment is populated from this project, so if you call your map property myMap within the datatype, you need to change location to myMap.

    e.g.

    var lat = CurrentPage.location.Latitude;
    

    becomes

    var lat = CurrentPage.myMap.Latitude;
    

    You will need to get your own API Key. I just followed the instructions on here: https://developers.google.com/maps/documentation/javascript/tutorial to get mine and then just replace the [YOUR-API-KEY] with your API in the code.

    You then place a Div where you want the map to display :

    <div id="map-canvas"></div>
    

    Simple!

Please Sign in or register to post replies

Write your reply to:

Draft