Has anybody been able to implement Google Maps v3 on a Web Part page (SharePoint 2010)?

The maps render fine if I display them in a separate .aspx page, but as soon as I try to embed the code in a Content Editor Web Part or a Form Web Part, I get a blank page. I did the test in both Internet Explorer and Firefox.

I'd be really interested to see a working example. Again, I have two constraints:

Update: I got this to work, below an example. Google sample: http://code.google.com/apis/maps/documentation/javascript/examples/map-simple.html

My test (note the explicit width and height on the div):

<div id="map_canvas" style="width:300px;height:300px;">placeholder</div>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var myLatlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
  zoom: 8,
  center: myLatlng,
  mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
</script>
link|improve this question

53% accept rate
feedback

2 Answers

up vote 4 down vote accepted

Yes, it is possible I have a version here. What method are you using to inject the Maps, are you injecting into a named div, or some other method? I have it working with CEWP; here is some sample code to put into your CEWP:

var myCenter = new google.maps.LatLng(0.0, 0.0);
var mapOptions = { zoom: 13, center: myCenter, mapTypeId: google.maps.MapTypeId.ROADMAP }
map = new google.maps.Map(document.getElementById("googlemap"), mapOptions);

You would then need within the text for the CEWP a div with id "googlemap".

link|improve this answer
Thanks Tim. Just to confirm: are we talking about v3? Would you mind showing the whole code, including how you load the scripts from Google? For my test, I just took examples from the Google site, like this one: code.google.com/apis/maps/documentation/javascript/examples/… – Christophe Jun 21 '11 at 13:06
Like this: <script src="https://maps-api-ssl.google.com/maps/api/js?sensor=false" type="text/javascript"></script> – Tim Ebenezer Jun 21 '11 at 13:40
Tim, your reply encouraged me to look further and finally make it work. What was missing in my case was an explicit width and height in the div style. – Christophe Jun 22 '11 at 1:17
feedback

I have a working template which I share within my company. It has been pretty successful in the implementation that even non-coder can re-use the same content.

The blank page you see when inserting in CEWP is due to the undeclared stylesheet. By inserting a reference link in the page header should solve the issue and render the map at full size.

<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />

With that reference you page will be rendered at full size (100% width height of the web part) and not limited to the size defined in your styling.

I have a brief example in here: http://sharepointgarage.blogspot.com/2012/05/list-to-google-map.html

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.