link in info window for streetview....

155 views
Skip to first unread message

duncanm

unread,
Oct 1, 2010, 4:57:16 PM10/1/10
to Google Maps JavaScript API v3
Hi,

I have a map with the following structure:

http://www.midwinterdesign.net/sample.html

and I would like to add a <a> link into the info window of each marker
that changes the map view to streetview centred on the marker (as if I
had dragged the pin man icon on to the marker)

Is this possible?

I already have the following data for each icon:

pov: {
heading: -127,
pitch: 5.8,
zoom: 0.5 }



duncanm

unread,
Oct 2, 2010, 8:23:16 AM10/2/10
to Google Maps JavaScript API v3
I've managed to get this far:

http://www.midwinterdesign.net/sample2.html

I can create a link that changes the map to streetview, however It's
centered on the centre of the map, and not on each individual icon.

Does anyone know what I must do to set each link to open at the lat -
long of each marker?


Thanks,

D.

--

Chad Killingsworth

unread,
Oct 2, 2010, 8:53:27 AM10/2/10
to Google Maps JavaScript API v3
You'll want to use the StreetViewService class. See
http://code.google.com/apis/maps/documentation/javascript/reference.html#StreetViewService

Specifically, you'll use the getPanoramaByLocation method. Use the
marker position as your location. One of the problems you'll likely
encounter is creating a proper closure on your marker event listener.
A search of these forums will give you the solution there.

Chad Killingsworth

Martin

unread,
Oct 2, 2010, 12:53:13 PM10/2/10
to Google Maps JavaScript API v3
Then once you have the nearest Street View you can use this function
to determine the POV angle to set your Street View to so it points to
your marker:

function getAngle( from, to){
function wrapAngle( angle){
if ( angle>=360) {
angle-=360;
} else if ( angle<0){
angle+=360;
}
return angle;
}
var DEGREE_PER_RADIAN=57.2957795, RADIAN_PER_DEGREE=0.017453;
var dLat= to.lat()- from.lat(), dLng= to.lng()- from.lng();
var yaw=Math.atan2( dLng*Math.cos( to.lat()*RADIAN_PER_DEGREE),
dLat)*DEGREE_PER_RADIAN;
return wrapAngle( yaw);
}

Pass it the lat,lng (from) of of the nearest Street View returned by
the StreetViewService() and use your marker lat,lng as the 'to'
parameter and it'll give you an angle to set the Street View to when
it opens.

Martin.
Reply all
Reply to author
Forward
0 new messages