James Lin
James Lin

Reputation: 26538

How to reuse the same google map street view object

I have a google map and some markers, on clicking the markers I want to open up a street view map, which can be closed and open up again.

I have tried using single global street view instance and using display:none to hide it, problem is, the map won't show render again after it has been hidden.

I also tried initiating new global instance every time, but looks like old instances are not destroyed, and renders new overlays on top of older overlays.

What's the best way to achieve this?

Edit:

Probably a separate question, if above is not easy to achieve, how do I switch existing map to street view mode, given a lat lng? I have been searching on google and couldn't find any apparent result.

Upvotes: 1

Views: 1054

Answers (1)

James Lin
James Lin

Reputation: 26538

OK, I was wrong about "I also tried initiating new global instance every time, but looks like old instances are not destroyed, and renders new overlays on top of older overlays." So it is workable.

And regarding to my question update, I got my answer from the following link:

https://developers.google.com/maps/documentation/javascript/examples/streetview-overlays

Here is the code in case you have similar purpose:

var sv = map.getStreetView();
sv.setPosition(new google.maps.LatLng(lat,lng));                                                                                                   
sv.setVisible(true); 

Upvotes: 1

Related Questions