Question

If you go to http://maps.google.com and zoom in until Google runs out of map the viewer automatically transitions to Streetview-mode (at least if Streetview is available at the location you zoomed in on).

I'm mucking around with the Google Maps v3 API. Is there a way to replicate the map-to-streetview effect here? I can enable Streetview just fine by putting streetViewControl: true in the mapOptions, but the user still has to manually drag the stickman onto the map to get Streetview going.

Was it helpful?

Solution

This will open a panorama at the map center:

var G = google.maps;
var svpContainer = document.getElementById('svp'); // Make sure this div exists
var svp = new G.StreetViewPanorama(svpContainer);
G.event.addListener(map, 'zoom_changed', function(){
    var z = map.getZoom();
    var center = map.getCenter();
    if (z > 15) {
        svp.setPosition(center);
        svp.setVisible(true);
    }

});

Tested over Dallas, TX. Make sure you have a div with id 'svp'

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top