Search code examples
javascriptgoogle-maps-api-3google-street-view

Google maps v3 street view pegmen position


How would I get street view pegmen offset position in div. I need it for placing infobox/tooltip beside pegmen. Is there any API call for creating infobox relative to pegmen or gettin his offset? Position of pegmen is changing according to maps control (if google maps canvas is smaller then 350px mini controls are implemented in it)


Solution

  • You can use

    var svpLatLon = map.getStreetView().getPosition();
    var dummy = new google.maps.OverlayView();
    var proj = dummy.getProjection();
    var pixel = proj.fromLatLngToContainerPixel(svpLatLon);
    

    Then you can read

    var x = pixel.x;
    var y = pixel.y;