I installed the Google Maps Datatype package and add the Google Map Datatype to one of my documenttype properties. Adding a Google Map location in the Umbraco Backoffice works perfect, but I can't seem to render it in the page.
My template looks like this:
<asp:content ContentPlaceHolderId="phMain" runat="server"> <div class="C00_Clean container"> <div class="sep"> <umbraco:Macro Alias="Activity" runat="server" /> <div id="map" class="map"> <umbraco:Item field="activityGoogleMap" runat="server" /> <script type="text/javascript"> $('div[class=map]').each(function() { $(this).addClass('mapdimensions'); var mapId = $(this).attr('id'); var value = $(this).html(); value = $.trim(value); var point = value.split(','); var lat = parseFloat(point[0]); var lon = parseFloat(point[1]); var zoom = parseFloat(point[2]); var p = new google.maps.LatLng(lat, lon); var myOptions = { center: p, zoom: zoom, mapTypeId: google.maps.MapTypeId.ROADMAP }; fm = new google.maps.Map(document.getElementById(mapId), myOptions); var marker = new google.maps.Marker({ position: p, title:"We are here!", animation: google.maps.Animation.BOUNCE });
// To add the marker to the map, call setMap(); marker.setMap(fm); }); </script> </div> </div> </div> </asp:content>
In my master template I have referenced the Google Map API:
Try moving your <script> tag outside of the <div class="map"> tag, as it think it may be causing an issue. Then in the JS, try changing the "var value = $(this).html();" to "var value = $(this).text();" ... so that you are only getting the text value, not the innerHTML.
Google Map not rendering in page
Hi,
I installed the Google Maps Datatype package and add the Google Map Datatype to one of my documenttype properties. Adding a Google Map location in the Umbraco Backoffice works perfect, but I can't seem to render it in the page.
My template looks like this:
<asp:content ContentPlaceHolderId="phMain" runat="server">
<div class="C00_Clean container">
<div class="sep">
<umbraco:Macro Alias="Activity" runat="server" />
<div id="map" class="map">
<umbraco:Item field="activityGoogleMap" runat="server" />
<script type="text/javascript">
$('div[class=map]').each(function()
{
$(this).addClass('mapdimensions');
var mapId = $(this).attr('id');
var value = $(this).html();
value = $.trim(value);
var point = value.split(',');
var lat = parseFloat(point[0]);
var lon = parseFloat(point[1]);
var zoom = parseFloat(point[2]);
var p = new google.maps.LatLng(lat, lon);
var myOptions = {
center: p,
zoom: zoom,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
fm = new google.maps.Map(document.getElementById(mapId),
myOptions);
var marker = new google.maps.Marker({
position: p,
title:"We are here!",
animation: google.maps.Animation.BOUNCE
});
// To add the marker to the map, call setMap();
marker.setMap(fm);
});
</script>
</div>
</div>
</div>
</asp:content>
In my master template I have referenced the Google Map API:
<script src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
I have noticed, that when I delete the Javascript in my template, the coördinates of the Google Map show up:
Am I missing something here?
Thanks for your help,
Anthony
Hi Anthony,
Try moving your <script> tag outside of the <div class="map"> tag, as it think it may be causing an issue. Then in the JS, try changing the "var value = $(this).html();" to "var value = $(this).text();" ... so that you are only getting the text value, not the innerHTML.
Cheers, Lee.
Hi Lee,
Thanks for your help,
I placed the script tag outside of the <div id="map"></div> like this
</script>
sorry for the bad layout, can't seem to edit it in this post.
But the Google Map still doesn't render in the page.
Do you get any JS errors in your browser?
No, the only thing that is rendered in the browser is:
I have tried the static Google map with the script of Darren's Blogpost:
<script type="text/javascript">
$(document).ready(function () {
$('div[class=map]').each(function() {
$(this).addClass('mapdimensions');
var mapId = $(this).attr('id');
var value = $(this).html();
value = $.trim(value);
var point = value.split(',');
var lat = parseFloat(point[0]);
var lon = parseFloat(point[1]);
var zoom = parseFloat(point[2]);
var apiKey = '.....';
var imgSrc = 'http://maps.google.com/staticmap?';
imgSrc += 'center='+lat+','+lon;
imgSrc += '&zoom=' + zoom;
imgSrc += '&markers='+lat+','+lon+',blues';
imgSrc += '&size=400x400';
imgSrc += '&key='+apiKey;
var imgTag = '<img height="400" alt="map" src="'+imgSrc+'" width="400">';
$(this).html(imgTag);
});
});
</script>
And this works!:
strange why the dynamic script isn't working.
Anthony
yay, I got the dynamic map working :)
I used Codex' modified JavaScript (see comments in Darren Ferguson's blogpost on displaying Google Maps using the Google Maps Datatype:
$('div[class=map]').each(function() {
$(this).addClass('mapdimensions');
var mapId = $(this).attr('id');
var value = $(this).html();
value = $.trim(value);
var point = value.split(',');
var lat = parseFloat(point[0]);
var lon = parseFloat(point[1]);
var zoom = parseFloat(point[2]);
var p = new google.maps.LatLng(lat, lon);
var myOptions = {
center: p,
zoom: zoom,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
fm = new google.maps.Map(document.getElementById(mapId),
myOptions);
var marker = new google.maps.Marker({
position: p,
title:"We are here!",
animation: google.maps.Animation.BOUNCE
});
// To add the marker to the map, call setMap();
marker.setMap(fm);
});
Thanks to Lee Kelleher for his help
Anthony
is working on a reply...