How to set correct heading for Google Maps JavaScript API Version 3 in case of postal address is specified?
Asked Answered
B

1

6

I am struggling with the following problem and can not find any solution in the Goolge Maps API docs or in the net, therefore I will try to post my question here:

I was using Googles Static StreetView Image API, where you can pass as a location a long/lat or a string with a postal address. In my case I was always using the string approach that contains in most cases the address with a housenumber. I was astonished by the results of the returned image, which was in most cases perfectly oriented in the direction to the searched address.

Now I wanted to give the JavaScript API for StreetViews a try. It works perfectly fine with the only available interface for a location through specifing the address through long/lat values. Through the optional pov parameters the heading can be specified too. But in case you want to initialize the StreetView with a postal address with a housenumber you are lost with that API. The only way is to geocode the postal address to a long/lat value through the Geocoding API but with the handicap of loosing the heading information. As a final result the initial StreetView image was completely different oriented in such a case.

I checked again the Static StreetView Image API and found following comment to the heading member:

heading (optional): ... If no heading is specified, a value will be calculated that directs the camera towards the specified location, from the point at which the closest photograph was taken.

Is there anything I can do here? How can I find the perfect heading between the position of the made photo to the location I am looking for? It seems only Google can do this through some internal magic for the Static StreetView Image API.

Birdlime answered 14/3, 2012 at 15:20 Comment(0)
J
5

1) Indeed geocode the postal address to a long/lat value, so you have the 'exact' location of the house.

2) Use streetViewService.getPanoramaByLocation to see if streetview is available, and the response will include the exact location where the streetview image was taken.

Now you can calculate the heading between both points (1 being 'the house', and 2 being 'the camera'). You can use the google.maps.geometry.spherical.computeHeading function for this - see https://developers.google.com/maps/documentation/javascript/geometry#Navigation

Jakoba answered 27/6, 2012 at 0:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.