Reputation: 37
I want to use Google Maps for Openlayers in my project. I try to integrate the maps with this: https://github.com/mapgears/ol3-google-maps. But I can't get even the simplest example to work. The map doesn't load (blank space), and in the console I get "ReferenceError: olgm is not defined". This is the code I have:
<script>
...code...
var googleLayer = new olgm.layer.Google();
var center = [-7908084, 6177492];
var map = new ol.Map({
interactions: olgm.interaction.defaults(),
controls: ol.control.defaults().extend([
overviewMapControl,
mousePositionControl,
new ol.control.ScaleLine()
]),
layers: [googleLayer],
target: 'map',
view: new ol.View({
center: center,//[0, 0],
zoom: 2
})
});
var olGM = new olgm.OLGoogleMaps({map: map}); // map is the ol.Map instance
olGM.activate();
...code...
</script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3&key=MYKEYHERE"></script>
<script src="js/ol3gm-debug.js"></script>
What can I possibly do wrong?
Upvotes: 1
Views: 985
Reputation: 6724
Put your script tag after "olg3m-debug.js" script tag. You need to check div id.
And put your script inside document ready for use DOM after initialize.
$( document ).ready(function() {
//your script goes here
});
Upvotes: 1