Im trying to add StreetView functionality to my OpenLayers web app, and would like to add the overlay showing StreetView availability to the map itself. I have seen an example of it being done successfully here, but i cannot get the code to work in my own solution. Specifically :

var layer = new OpenLayers.Layer.Google("Google Street", {sphericalMercator: true});

layer.mapObject.addOverlay(new GStreetviewOverlay());

results in the error:

layer.mapObject is null

Has anyone got any idea what i might be doing wrong, and if so, how can I fix this?

3 Answers 3


Openlayers with Streetview

requires the GeoExt ux extension

all the code is available - so you can see what you are missing

(if you could post a live link to your current map - users could debug it for you.)

enter image description here



To use Google layers and meet licensing requirements you have to access Google layers through the Google API. When you add a Google layer to an OpenLayers map OpenLayers loads the Google API.

The layer.mapObject (as opposed to layer.map which is the OL map object) should give you a reference to the Google Map. As this is null something has gone wrong loading the Google API. You can check in FireBug if it has loaded correctly.

The example you point to may be using the older Google 2 API rather than version 3. You no longer need an API key and can add in the Google API using:

<script src="http://maps.google.com/maps/api/js?sensor=false"></script>

Have a look at the unit tests for the Google v3 API layers which may help you.

Remember the StreetView also needs Flash in the browser.

  • Hi there, thanks for your help. I'm not at my desk right now so I'm not going to be able to test your suggestions, but here's what I know: I'm definitely loading the Google Maps API v3. I have implemented StreetView in Web Apps before, but this time I'm looking to get the overlay on the map as well. Im wondering though if its a browser thing. The website I gave a link for works fine in IE (8) but not in Firefox... any ideas? Sep 5, 2011 at 20:28
  • The demo doesn't work for me in FF6, IE8 or IE9. It seems to only show either a map or a street view.. Sep 5, 2011 at 20:44
  • Hmmm, the website seems to work in my IE8 here.... going to consult the OpenLayers user list as well now! Sep 6, 2011 at 9:12

The reason why layer.mapObject is null is that the mapObject property is created after that the layer is added to the map. Try this:

var layer = new OpenLayers.Layer.Google("Google Street", {sphericalMercator: true});
layer.mapObject.addOverlay(new GStreetviewOverlay());

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.