computing pov for streetview from a geocoded address?

671 views
Skip to first unread message

fearless_fool

unread,
Feb 1, 2011, 2:27:54 PM2/1/11
to google-map...@googlegroups.com
So I've got a geocoded house address, returned by geocoder.geocode(...).  I'd like to display a streetview of the geocoded address with the POV facing the house.  Can someone point me to a concise v3 example of how to go about this, or at least a hint or two?  (Extra credit if the solution shows how to determine if a streetview is available at all!)

TIA.

- ff

Marc Ridey

unread,
Feb 1, 2011, 3:14:19 PM2/1/11
to google-map...@googlegroups.com
Check this on how to determine if a StreetView panorama exists for a given LatLng.

--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Robert Poor

unread,
Feb 1, 2011, 4:26:29 PM2/1/11
to google-map...@googlegroups.com
@marc:

On Tue, Feb 1, 2011 at 12:14, Marc Ridey <mri...@google.com> wrote:
Check this on how to determine if a StreetView panorama exists for a given LatLng.

Nice -- to summarize, call getPanoramaByLocation() and the status returned in the callback function tells you if a StreetView is available at that location.  Simple enough.

Now all I need is to figure out how to set the POV.  I'm pretty sure it's not too difficult, but I haven't found a clean V3 example.

- ff

Marc Ridey

unread,
Feb 1, 2011, 4:54:47 PM2/1/11
to google-map...@googlegroups.com
See http://blog.mridey.com/2010/05/enabling-and-initializing-street-view.html

Just call panorama.setPov() 

one trick:

You give StreetViewService the latlng of the location you would like to look at but StreetViewService comes back with the latlng of the location where the StreetView photos where taken. So you need to set the heading of the POV to the heading from where StreetView is to where you wanted to be.
For that you need something like:  http://www.movable-type.co.uk/scripts/latlong.html or any formula calculating a bearing between two LatLngs.

Marc


- ff

--

Martin

unread,
Feb 1, 2011, 9:43:25 PM2/1/11
to Google Maps JavaScript API v3
Try this:

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);
}

'from' and 'to' are both LatLng objects.

Martin.


On Feb 1, 9:54 pm, Marc Ridey <mri...@google.com> wrote:
> Seehttp://blog.mridey.com/2010/05/enabling-and-initializing-street-view....
>
> Just call panorama.setPov()
>
> one trick:
>
> You give StreetViewService the latlng of the location you would like to look
> at but StreetViewService comes back with the latlng of the location where
> the StreetView photos where taken. So you need to set the heading of the POV
> to the heading from where StreetView is to where you wanted to be.
> For that you need something like:http://www.movable-type.co.uk/scripts/latlong.htmlor any formula
> calculating a bearing between two LatLngs.
>
> Marc
>
> On Tue, Feb 1, 2011 at 4:26 PM, Robert Poor <rdp...@gmail.com> wrote:
> > @marc:
>
> > On Tue, Feb 1, 2011 at 12:14, Marc Ridey <mri...@google.com> wrote:
>
> > Check this on how to determine if a StreetView panorama exists for a given
> >> LatLng.
> >>http://blog.mridey.com/2010/11/using-streetviewservice-in-maps-api.html
>
> > Nice -- to summarize, call getPanoramaByLocation() and the status returned
> > in the callback function tells you if a StreetView is available at that
> > location.  Simple enough.
>
> > Now all I need is to figure out how to set the POV.  I'm pretty sure it's
> > not too difficult, but I haven't found a clean V3 example.
>
> > - ff
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Google Maps JavaScript API v3" group.
> > To post to this group, send email to
> > google-map...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-maps-js-a...@googlegroups.com<google-maps-js-api-v3%2Bunsu...@googlegroups.com>
> > .

Robert Poor

unread,
Feb 1, 2011, 10:00:23 PM2/1/11
to google-map...@googlegroups.com
Martin:

On Tue, Feb 1, 2011 at 18:43, Martin <warw...@gmail.com> wrote:
Try this:

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);
}

'from' and 'to' are both LatLng objects.

Martin.

yaw looks like a simplified version of the forward azimuth algo on the previously cited movable_type site (no?).  

But now I am curious: what purpose is wrapAngle() serving?  It is always the case that -PI <= Math.atan2() <= PI -- does the Google StreetViewPov class really care if you give it a negative heading?

JKurtock

unread,
Feb 2, 2011, 12:13:50 AM2/2/11
to Google Maps JavaScript API v3
Or you can let Mr. Google compute the heading from the pair of
latlngs. http://code.google.com/apis/maps/documentation/javascript/geometry.html

Robert Poor

unread,
Feb 2, 2011, 12:51:59 AM2/2/11
to google-map...@googlegroups.com
@JKurtock:

On Tue, Feb 1, 2011 at 21:13, JKurtock <jkur...@gmail.com> wrote:
Or you can let Mr. Google compute the heading from the pair of
latlngs. http://code.google.com/apis/maps/documentation/javascript/geometry.html

That's the first sensible answer I've heard!  :)  Thanks for bringing that to light.

- ff 

Marc Ridey

unread,
Feb 2, 2011, 8:46:56 AM2/2/11
to google-map...@googlegroups.com
Cool!!! new stuff I didn't know about. Thanks.

--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages