[GIS] Working out street view heading

google mapsgoogle-maps-apigoogle-street-view

I was wondering if it is possible to work out a POV heading for street view based on a GPS coordinate?

For instance, say I have the coordinate '43.6653055692 -79.3102166453'

If I plugin the coordinates into the maps API to create interactive street view:

var myLatlng = new google.maps.LatLng(43.6653055692, -79.3102166453);
var panoramaOptions = {
    position: myLatlng,
};

var panorama = new google.maps.StreetViewPanorama(document.getElementById('street-canvas'), panoramaOptions);
map.setStreetView(panorama);

If finds the closet street view coordinate to the coordinate that I gave, but it doesn't direct the 'camera' towards the coordinate, like the static image API does. I want it to be pointing to the GPS coordinate. This seems to work when doing it for static images, but not for the interactive maps. Is there an option I'm missing?

Static Image URL:
https://maps.googleapis.com/maps/api/streetview?location=43.6653055692,-79.3102166453&size=600×400

Best Answer

I think you can use the google.maps.geometry.spherical.computeHeading method.

See documentation here: https://developers.google.com/maps/documentation/javascript/geometry#Navigation

Related Question