That works an absolute treat! Thank you. For reference, here is the same link I gave earlier in the thread with the camera now automatically orienting towards the marker: http://www.planningalerts.org.au/applications/6549
Thanks again Marc! Matthew On May 29, 10:20 pm, Marc Ridey <[email protected]> wrote: > try to monitor position_changed on the panorama. the Latlng should be set to > the LatLng of the panorama instead of the latlng you requested and at that > point, you could calculate the headig to set the pov. > > On Sat, May 29, 2010 at 1:04 PM, Matthew Landauer <[email protected]>wrote: > > > > > Hi Marc, > > > Thanks for your reply! > > > Unfortunately, your example doesn't fix the problem I'm having. I'll > > do my best to explain. I have a location I want to view. So, what I do > > is request a panorama for that location. Nine times out of ten the > > panorama returned is not actually for that location, it's somewhere > > nearby. A good example is I have a location of a house and when I > > request a panorama for the house's location it returns the panorama > > for a location in the street which is obviously a few metres away from > > the original requested location. > > > The problem I have then is that I want to find out what the _actual_ > > location of the panorama returned is rather than the one I requested. > > That way then I can orient the view (using similar code to what you > > showed) towards the point of interest. > > > I hope that makes it a little clearer. > > > All the best, > > Matthew > > > On May 27, 5:14 pm, Marc Ridey <[email protected]> wrote: > > > Try this. Drag the pegman on the map and the streetview panorama will > > > point towards the marker on open. Drag the marker and the streetview > > > panorama will follow. > > > > <html> > > > <head> > > > <script type="text/javascript" > > > src="http://maps.google.com/maps/api/js?sensor=false"></script> > > > <script> > > > function initialize() { > > > var opts = { > > > center: new google.maps.LatLng(48.8589, 2.2958), > > > zoom: 14, > > > mapTypeId: google.maps.MapTypeId.ROADMAP, > > > streetViewControl: true > > > }; > > > > var map = new google.maps.Map(document.getElementById('map'), > > opts); > > > var panorama = new > > > google.maps.StreetViewPanorama(document.getElementById('streetview')); > > > map.setStreetView(panorama); > > > > var marker = new google.maps.Marker({ > > > position: opts.center, > > > draggable: true > > > }); > > > marker.setMap(map); > > > > function refreshPanoPov() { > > > var markerPos = marker.getPosition(); > > > var panoPos = panorama.getPosition(); > > > if (markerPos && panoPos) { > > > var markerPosLat = markerPos.lat() / 180 * Math.PI; > > > var markerPosLng = markerPos.lng() / 180 * Math.PI; > > > var panoPosLat = panoPos.lat() / 180 * Math.PI; > > > var panoPosLng = panoPos.lng() / 180 * Math.PI; > > > > var y = Math.sin(markerPosLng - panoPosLng) * > > > Math.cos(markerPosLat); > > > var x = Math.cos(panoPosLat)*Math.sin(markerPosLat) - > > > > Math.sin(panoPosLat)*Math.cos(markerPosLat)*Math.cos(markerPosLng - > > > panoPosLng); > > > var brng = Math.atan2(y, x) / Math.PI * 180; > > > > var pov = panorama.getPov(); > > > pov.heading = brng; > > > panorama.setPov(pov); > > > } > > > } > > > > google.maps.event.addListener(marker, 'position_changed', > > > refreshPanoPov); > > > google.maps.event.addListener(panorama, 'position_changed', > > > refreshPanoPov); > > > } > > > </script> > > > </head> > > > <body style="margin:0; padding:0" onload="initialize()"> > > > <div id="map" style="width: 400px; height: 400px;"></div> > > > <div id="streetview" style="position:absolute; left:410px; top: > > > 0px; width: 400px; height: 400px;"></div> > > > </body> > > > </html> > > > -- > > You received this message because you are subscribed to the Google Groups > > "Google Maps JavaScript API v3" group. > > To post to this group, send email to > > [email protected]. > > To unsubscribe from this group, send email to > > [email protected]<google-maps-js-api-v3%2B > > [email protected]> > > . > > For more options, visit this group at > >http://groups.google.com/group/google-maps-js-api-v3?hl=en. -- You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.
