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.