Detect when the streetview pegman has been dropped onto the map

1,321 views
Skip to first unread message

spiderplant0

unread,
Dec 8, 2011, 11:32:47 AM12/8/11
to google-map...@googlegroups.com
I am building a site where the Google map and Google street-view are in separate DIVs. I want to detect when the user has dropped the little yellow man onto the map so I can switch the display from the map to the streetview. Is there an event for this?

I guess there must be a way to do this as, in Google's regular map website (maps.google.com), the street view overlay only gets displayed only when the pegman is dropped.

Marcelo

unread,
Dec 8, 2011, 12:24:51 PM12/8/11
to Google Maps JavaScript API v3
On Dec 8, 9:32 am, spiderplant0 <spiderpla...@gmail.com> wrote:
> I am building a site where the Google map and Google street-view are in
> separate DIVs. I want to detect when the user has dropped the little yellow
> man onto the map so I can switch the display from the map to the
> streetview. Is there an event for this?

Did you read the documentation?
http://code.google.com/apis/maps/documentation/javascript/reference.html#StreetViewPanorama
Event visible_changed

--
Marcelo - http://maps.forum.nu
--

spiderplant0

unread,
Dec 8, 2011, 5:07:45 PM12/8/11
to Google Maps JavaScript API v3
Thanks but this is not really it.

visibile_changed works somewhat but also fires at initialisation and
when you park the pegman etc.
This bug ..
http://code.google.com/p/gmaps-api-issues/issues/detail?id=2972&can=1&q=pegman&colspec=ID%20Type%20Status%20Introduced%20Fixed%20Summary%20Stars%20ApiType%20Internal

... describes a similar issues of detecting pegman dropping. Assuming
someone hasnt forgotten to close it, the issue still exists. It
mentions a work around by detecting the blue street view overlay which
sounds promising. But wasnt sure how to detect this.

Has anyone out there come across this issue and do you have any work
arounds?

Marcelo

unread,
Dec 8, 2011, 5:53:47 PM12/8/11
to Google Maps JavaScript API v3
On Dec 8, 3:07 pm, spiderplant0 <spiderpla...@gmail.com> wrote:
> Thanks but this is not really it.
>
> visibile_changed works somewhat but also fires at initialisation and
> when you park the pegman etc.

Obviously, I don't know enough about what you're trying to achieve so
I can only answer based on the few lines of text that you posted.
A link to your map describing what you want to happen would help.

--
Marcelo - http://maps.forum.nu
--

> This bug ..http://code.google.com/p/gmaps-api-issues/issues/detail?id=2972&can=1...

spiderplant0

unread,
Dec 10, 2011, 8:33:16 AM12/10/11
to Google Maps JavaScript API v3
Here's a fork of the code I'm using to prototype...
jsfiddle.net/spiderplant0/fubNj/
This should help you understand the issues with visibility_changed
etc.
The question is pretty simple: Detect if, and only if, the pegman has
been dropped onto the map.
Thanks.

Marcelo

unread,
Dec 10, 2011, 9:17:17 AM12/10/11
to Google Maps JavaScript API v3
What is your definition of "the pegman has been dropped onto the
map"?
When the user moves the pegman from one position to another, it is
also "dropped on the map", but does that count, or is it only the
first drop that you're looking for?

If visible_changed doesn't suit your purposes then perhaps you can use
pano_changed and check getPosition() in the event handler. If you only
want to act on the first drop you can make "position" a global
variable and compare it to the last position in the event handler, for
example

var position; //global
var lastPosition = null; //global
// ...

var svp = new G.StreetViewPanorama(svpContainer,svpOptions);

G.event.addListener(svp, 'pano_changed', function(){
position = svp.getPosition();
if (typeof position != 'undefined') {
//pegman has been dropped on a valid position
if (lastPosition) {
// This is not the first drop. Do noting.
}
else {
// This is the first drop.
// add whatever action you want to take on the first drop
}
lastPosition = position;
}
else {
lastPosition = null;
}
});


--
Marcelo - http://maps.forum.nu
--

Marcelo

unread,
Dec 10, 2011, 9:22:48 AM12/10/11
to Google Maps JavaScript API v3
I should add to the above code:

var G = google.maps; // global
// Sorry, I can't be bothered typing "google.maps." every time. ;-)


--
Marcelo - http://maps.forum.nu
--

> Marcelo -http://maps.forum.nu

Pil

unread,
Dec 10, 2011, 9:54:58 AM12/10/11
to Google Maps JavaScript API v3

On Dec 10, 3:22 pm, Marcelo <marcelo...@hotmail.com> wrote:

> var G = google.maps; // global
> // Sorry, I can't be bothered typing "google.maps." every time. ;-)


I wouldn't say this is laziness, it's good practice - as long as it is
not global.

spiderplant0

unread,
Dec 10, 2011, 11:34:06 AM12/10/11
to Google Maps JavaScript API v3
Thanks for the code suggestion Marcelo, it doesnt deal with the issue
of firing at initialisation (page load) etc. By drop I mean the
initial drop from his parking place onto the map or lift him up and
drop again. "visibile_changed" (at least on its own) is really not up
to it - if you have a play around with the fiddle you'll see it
activates even if you pan the streetview (this is counter to what the
documentation suggests).

I've added getPosition() and pano_changed etc to the fiddle - it
prints them out to see whats happening. Have a go.
http://jsfiddle.net/spiderplant0/UmPEq/17/

I guess my biggest issue is the firing of visibile_changed on page
load. I thought of ignoring it if its not followed by a
position_changed or something. But I cant think of a way that is not a
bit dodgy - so I rather have something a bit more robust.

An other idea was that mentioned in the bug report - detect insert_at
etc for the blue overlay loading. SOunds like it might be a bit over
complicated though. I've no idea how to do this. Any ideas?

spiderplant0

unread,
Dec 10, 2011, 11:37:03 AM12/10/11
to Google Maps JavaScript API v3
oops wrong fiddle link. try this one....
http://jsfiddle.net/spiderplant0/fubNj/7/

spiderplant0

unread,
Dec 10, 2011, 11:49:29 AM12/10/11
to Google Maps JavaScript API v3
..also in case theres any confusion, when I said to "pan the
streetView". I really mean clciking on the big arrow symbols that move
street view along the road.
Reply all
Reply to author
Forward
0 new messages