Question

I've got a StreetViewPanorama identified by my Lat Lng coordinates. My Lat and Lng coordinates are not exactly on the road from which Google car took the picture, but they are in the center of the building that I want to see in StreetView's picture. So I have 2 couple of coordinates, and I think that it's possible to calculate POV degrees to obtain a correct shot of the building. What I need is how to get the Lon Lat of the point in which is automatically placed "the man", so that I can calculate the correct POV degrees.

Was it helpful?

Solution 2

Problem solved:

// d is the position of the house or fisical element where I want to point the view
var d = {lat: 43.538524840485, lng: 10.322718769311};
var whereToLookLatLng = new google.maps.LatLng(parseFloat(d.lat), parseFloat(d.lng));
var panorama = new google.maps.StreetViewPanorama(
    document.getElementById('pano'),
    panoramaOptions
);
map.setStreetView(panorama);

var service = new google.maps.StreetViewService;
// With this function I get the panorama, if available, next the house or fisical element where I want to point the view 
service.getPanoramaByLocation(panorama.getPosition(), 50, 
    function(panoData) {
        if (panoData != null) {
            // MamLatLng is the position of the point of view
            var ManLatLng = panoData.location.latLng;
            // Now I calculate the heading to point the view in the direction of whereToLookLatLng
            var heading = google.maps.geometry.spherical.computeHeading(ManLatLng, whereToLookLatLng);
            var pov = panorama.getPov();
            pov.heading = heading;
            panorama.setPov(pov);
        }
    });
}

OTHER TIPS

My implementation of kiks73's solution.

Make sure to add the geometry library when loading the maps api:

https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=visualization,places,geometry&sensor=true

var dist = 50;

service.getPanoramaByLocation(targetLatLng, dist, function(panoData){
    panoramaLatLng = panoData.location.latLng;
    initStreetView(targetLatLng, panoramaLatLng)    
});

function initStreetView(targetLatLng, panoramaLatLng){

    var panoramaOptions = {
        position: targetLatLng
    };

    var streetView = new google.maps.StreetViewPanorama(document.getElementById('streetView'),panoramaOptions);
    var heading = google.maps.geometry.spherical.computeHeading(panoramaLatLng, targetLatLng);
    map.setStreetView(streetView);      
    streetView.setPov({heading:heading, pitch:0});                  

}               
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top