Getting location of streetview panorama in API v3

2,097 views
Skip to first unread message

Matthew Landauer

unread,
May 27, 2010, 2:38:34 AM5/27/10
to Google Maps JavaScript API v3
First off - thanks hugely for the introduction of streetview into the
maps API v3. Bonus that it doesn't use flash!

I was so excited that I moved over my website planningalerts.org.au to
use the v3 streetview the same day I found it was available. See here
for an example: http://www.planningalerts.org.au/applications/6549

The page basically shows the user the location of a planning
application for a water tank that is has been put into the local
council.

The addition of support for markers was great too. Thanks!

I do have one thing that I tried to do but for the life of me couldn't
figure out how to do. I want to orient the view automatically to point
towards the marker which is the actual location I'm interested in.

With the v2 API I did this by using this example:
http://gmaps-samples.googlecode.com/svn/trunk/streetview/angletowardsbuilding.html

So, what I tried is requesting a panorama from the location I'm
interested in (the same as the marker location). It then gives me
something close which hopefully will have the marker viewable in it.

But once that panorama is loaded if I query it's location it's not the
actual location of the panorama, just the location I requested
initially.

So, is there a way to do what the example
http://gmaps-samples.googlecode.com/svn/trunk/streetview/angletowardsbuilding.html
does with API v3?

Marc Ridey

unread,
May 27, 2010, 3:14:43 AM5/27/10
to google-map...@googlegroups.com
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>

Matthew Landauer

unread,
May 28, 2010, 11:04:07 PM5/28/10
to Google Maps JavaScript API v3
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

Marc Ridey

unread,
May 29, 2010, 8:20:50 AM5/29/10
to google-map...@googlegroups.com
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.

--
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 google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.


Matthew Landauer

unread,
May 30, 2010, 3:24:01 AM5/30/10
to Google Maps JavaScript API v3
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 <mri...@google.com> 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.
>
> > google-maps-js-a...@googlegroups.com<google-maps-js-api-v3%2B unsub...@googlegroups.com>
> > .

Kurteknikk

unread,
Jun 16, 2010, 4:31:17 AM6/16/10
to Google Maps JavaScript API v3
Hi,

I've got the street view showing correctly. But i would like to know
how to enable the different cursor and that box thing to show the user
if he's able to zoom or move in a particular direction/position.

I hope i explained myself well, thanks :)

Marc Ridey

unread,
Jun 17, 2010, 10:20:27 PM6/17/10
to google-map...@googlegroups.com
Not sure what you mean by the different cursor.
The box (ClickToZoom) and circle (ClickToGo) displayed in the Flash version of StreetView used on the maps side are not currently available in Maps Javascript API v3.

--
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 google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.

Kurt Agius

unread,
Jun 19, 2010, 7:36:29 PM6/19/10
to google-map...@googlegroups.com
So how does google do it ? Because they use google maps API v3 and they still use the flash version of the street view...

Chad Killingsworth

unread,
Jun 19, 2010, 11:54:16 PM6/19/10
to Google Maps JavaScript API v3
maps.google.com does not currently use the v3 API.
The v3 API does not use flash for street view and does not support
those features.

Chad Killingsworth

On Jun 19, 6:36 pm, Kurt Agius <kurtekn...@gmail.com> wrote:
> So how does google do it ? Because they use google maps API v3 and they
> still use the flash version of the street view...
>
>
>
> On Fri, Jun 18, 2010 at 4:20 AM, Marc Ridey <mri...@google.com> wrote:
> > Not sure what you mean by the different cursor.
> > The box (ClickToZoom) and circle (ClickToGo) displayed in the Flash version
> > of StreetView used on the maps side are not currently available in Maps
> > Javascript API v3.
>
> >> google-maps-js-a...@googlegroups.com<google-maps-js-api-v3%2B unsub...@googlegroups.com>
> >> .
> >> 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
> > google-map...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-maps-js-a...@googlegroups.com<google-maps-js-api-v3%2B unsub...@googlegroups.com>
> > .

Kurt Agius

unread,
Jun 20, 2010, 2:37:11 PM6/20/10
to google-map...@googlegroups.com
:-| are you sure ? I mean they're got a new API version with new features like drag and zoom, which if i'm not mistaken its only available for api v3... and they're using api v2 ??

I'll give it a look mate...

To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.

Chad Killingsworth

unread,
Jun 20, 2010, 7:15:27 PM6/20/10
to Google Maps JavaScript API v3
I'm sure. See
http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/41cfdef46c447e19/7224f338411661a6#7224f338411661a6

Chad Killingsworth
> > > >> google-maps-js-a...@googlegroups.com<google-maps-js-api-v3%2B unsub...@googlegroups.com><google-maps-js-api-v3%2B
> > unsub...@googlegroups.com>
> > > >> .
> > > >> 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
> > > > google-map...@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > > > google-maps-js-a...@googlegroups.com<google-maps-js-api-v3%2B unsub...@googlegroups.com><google-maps-js-api-v3%2B

Kurt Agius

unread,
Jun 21, 2010, 7:19:02 AM6/21/10
to google-map...@googlegroups.com
Ohh ic... 10x. Actually about my issue i saw an open issue that someone requested what i need to be available in the html version. Actually its just the box (click to go) and the circle... because the blur effect and the fullscreen are a bit difficult to have in html because still i'm not able to use HTML 5 because of the IE6 support...

Anyway thanks a lot for your help... i'll see how things go about the open issue, because its still new...

To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages