Google Street View heading issue
Asked Answered
H

1

2

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

Helbona answered 10/8, 2012 at 10:51 Comment(3)
0 is north. You need to either know or calculate the direction to the road to make this work. Since a "postcode" is not a physical location, that will be difficult.Detonator
Thanks, I have an idea.. if I can set the heading towards the next panaroma (I can get a unique panaroma id) then it will head towards the street. Have you got any idea how to implement that?Helbona
The documentation is always a useful resource. I would investigate the getLinks() function of google.maps.StreetViewPanoramaDetonator
H
8

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
    });
});
Helbona answered 14/8, 2012 at 11:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.