I think you have to call the Google maps code first and then put your “initialize” code in a separate script element.
<script src="http://maps.googleapis.com/maps/api/js"></script>
<script type="text/javascript">
function initialize() {var center = new google.maps.LatLng(...
</script>
There doesn’t seem to be anything wrong from what I can see. Could you copy and paste the entire controller and googleMap.html files? Then select the code and use the formatting button for code that looks like this: </>
I also realized that there is another issue. When you access the server URL without previewing this error occurs:
TypeError: <script src="http://maps.googleapis.com/maps/api/js">
function initialize() {var center = new
google.maps.LatLng(59.668551,10.766806); var mapProp = {center:center,
zoom: 13, mapTypeId:google.maps.MapTypeId.ROADMAP, scrollwheel: false
};var map = new google.maps.Map(document.getElementById("map"),mapProp);
var marker = new google.maps.Marker({ position:center});
marker.setMap(map);} google.maps.event.addDomListener(window, "load",
initialize);</script> has no such function "push"
(com.enonic.xp.resource.ResourceProblemException)
If you preview the page in the admin console this error does not occur.
Also, don’t put your google map in an <img /> tag - put it in a <div></div>.
The push error you’re receiving is because a different place in your application tries to add to the headEnd page contribution array - which is currently a string. If you this instead, the error will go away:
return {
// Put the maps' javascript into the head of the document
pageContributions: {
headEnd: [ defaultMap ]
}
};
TypeError: <script
src="http://maps.googleapis.com/maps/api/js"></script><script>function
initMap() {var myLatlng = new google.maps.LatLng(59.668080,
10.766901);var mapOptions = {zoom:13,center:
myLatlng,mapTypeId:google.maps.MapTypeId.ROADMAP};var map = new
google.maps.Map(document.getElementById("map"),
mapOptions);}google.maps.event.addDomListener(window, "load",
initMap);</script> has no such function "push"
(com.enonic.xp.resource.ResourceProblemException)
In com.vetinst:/site/filters/ga-report.js at line 2624
snippet += '<!-- End Google Analytics -->';
res.pageContributions.headEnd.push(snippet);27
return res;
Looks like the issue comes from a collision with the google analytics app (source code here), which tries to push another entry to the headEnd array. That’s an error with that application, and I filed a bug report with them on Github. That being said - since you’re creating an array, this issue shouldn’t happen. But oh well.
I suggest that you just sidestep the entire issue by switching out headEnd with bodyEnd.
Thanks Kristofer. I merged the pull request and we should make a 1.2.0 release soon. I’ll also make a note in the docs that page contributions should always be added as an array and that they should be checked first in the filters.