Google Street View heading issue

2019-02-19 06:35发布

问题:

I'm working in a project where I need to show google map street view heading towards road.

I've set the heading: 0 for the panorama object. But for different location it shows the heading differently. for example in some cases it shows heading towards street, for some locations it shows heading towards home.

panorama = theMap.getStreetView();
panorama.setPosition(new google.maps.LatLng(<?php echo $lat; ?>, <?php echo $lng; ?>););
panorama.setPov({
    heading: 0,
    zoom:1,
    pitch:0
});

If there any way can fix the heading towards street for all post codes?

Thanks

回答1:

Finally I found a very easy solution..

For the street view there's two links to navigate, that point towards street. I just read those heading and set the street view POV towards that direction. Here's full code.

var panoramaOptions = {
    position: langlongObj,
    visible: true
};
var panorama = new  google.maps.StreetViewPanorama(document.getElementById("map_canvas"), panoramaOptions);
map.setStreetView(panorama);

google.maps.event.addListener(panorama, 'links_changed', function() {
    var links =  panorama.getLinks();

    panorama.setPov({                   
        heading: links[0].heading,
        pitch: 0,
        zoom: 1
    });
});