1
<script src="openlayers.js"></script>    
<script src="http://maps.google.com/maps/api/js?v=3&amp;sensor=false"></script>
    <script type="text/javascript">
....
  var google = new OpenLayers.Layer.Google(
            "Google Streets", // the default
            {numZoomLevels: 20}
        );
....
   map.addLayers([
      main_layer,
      google
   ]);
....
</script>

Before adding the Google Maps Layer like this, everything worked. Now I get an TypeError: google.maps is undefined. What is wrong?


Please tell me if I totally misunderstood the concept of adding a google maps layer to openlayers

  • Looks like you are importing google maps api, which you don't need, and not open layers, which you do – John Powell Oct 22 '14 at 21:27
  • I DO import open layers as well, and even if I ommit the line <script src="http://maps.google.com/maps/api/js?v=3&amp;sensor=false"></script>, I still get the same error. – Ferenjito Oct 23 '14 at 8:27
  • Which version of Ol are you using. I mean 2.x.x not 2 or 3. Sometimes the function defs change. – John Powell Oct 23 '14 at 12:16
  • I am using OpenLayers 2.14 – Ferenjito Oct 23 '14 at 13:11
1

I solved it. The problem is the variable 'google', which overwrites something as it can be imagined.

I call it 'google_layer', now it works - no, it still does not work but at least it does not bring any JS error.

  • ah great, i couldnt work it out either, but now i see its obvious, i was using a variable named google... – Hayden Thring Sep 7 '15 at 5:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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