Skip to content
Advertisement

Find correct streetview from Google maps URL without using computeheading

I am using the computeHeading code from a previous answer by Geocodezip which mostly works fine but with some hiccups which are not Geocodezips fault. The variable “heading” recieves the computeHeading result and this data positions the heading view for google maps streetview like this:

JavaScript

However this is not always accurate. What I would like to achieve is pass the heading value from Google maps URL’s to the variable “heading”. I can strip out the heading value, parse it from an XML file, and echo the result in an infowindow on a working map. If you copy and paste the code below you can see that process working at 100%, but the POV (Point Of View) is slightly off (you need to rotate the street view) due to computeHeading, yet when I try to pass the value of the variable “NEWHEADING” to “heading” it is not being read and the POV defects to default north… in other words “0”. I have tried “rearranging” the code flow but without success.

I have validated this code in JSHint and JSLint and console

There are no working examples of this idea anywhere, I have been through all of google search to page 30. All other examples I have seen use computeHeading which I do not want to use. I want to use the value of the NEWHEADING variable from the parsed XML for the heading to create the correct StreetView POV. I hope I have been clear enough and any help and suggestions will be greatly appreciated.

JavaScript

Advertisement

Answer

Pass the desired heading into the createMarker function and use that instead of calculating it from the street view panorama location and the “looked at” location.

JavaScript

working fiddle

code snippet:

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement