Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 877
Alathink Avatar asked Mar 14 '12 15:03

Alathink


People also ask

How do I get headings on Google Maps?

Finding North Using Google Maps This means that, as long as your blue icon has a beam that points upwards, you're heading north. If it's pointing downwards, you're heading south, etc. To do this, tap the compass icon in the top-right corner of the Google Maps map view.

How is the global namespace referred for marker object in version 3 of the API as compared to version 2?

Probably the most noticeable change in the Maps JavaScript API v3 is the introduction of the google. maps namespace. The v2 API places all objects in the Global namespace by default, which can result in naming collisions. Within v3, all objects are located within the google.

How do you fix you have included the Google Maps JavaScript API multiple times on this page this may cause unexpected errors?

"You have included the Google Maps JavaScript API multiple times on this page. This may cause unexpected errors." To fix this, please check in your settings if you've also set the Google Maps API in another plugin configuration.


1 Answers

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

like image 149
Hans Avatar answered Nov 19 '22 14:11

Hans