Map boundaries when zoom out

207 views
Skip to first unread message

THE_AI

unread,
Feb 23, 2012, 2:05:41 PM2/23/12
to google-map...@googlegroups.com
Hey guys!
I use the boundaries of the map to create an ajax request and restrict the markers that it returns. Everything works really great when I'm zoomed in, but when I'm zoomed out I can see the whole map of the world in front of me, but the boundaries for east and west are stating -79 east and +134 west.
Here is an example:
http://snag.gy/fv6pK.jpg

Because of that my sql returns no results...

Any ideas what I could do?
Thanks,
Daniel

Rossko

unread,
Feb 23, 2012, 3:16:16 PM2/23/12
to Google Maps JavaScript API v3
> but when I'm zoomed out I can see the whole map of the world in front of
> me, but the boundaries for east and west are stating -79 east and +134
> west.

Example discussion from a few years back
http://groups.google.com/group/google-maps-api/browse_thread/thread/dca7b6c38883d0f3/5e85fd1efe956f82

THE_AI

unread,
Feb 24, 2012, 5:24:57 AM2/24/12
to google-map...@googlegroups.com
Hey Rossko,
thanks for your reply. I had a look at those threads and in a matter of fact I take in account the dateline. I use the example from this book:

http://books.google.fr/books?id=GNMCdlkKU3sC&printsec=frontcover&hl=fr&source=gbs_ge_summary_r&cad=0#v=onepage&q&f=false

You can see the php code on page 153. My where query look like this:

if($nelng  > $swlng) {
                $where[] = ' (m.gmlng > ' . $swlng . ' AND m.gmlng < ' . $nelng . ')';
                $where[] = ' (m.gmlat <= ' . $nelat . ' AND m.gmlat >= ' . $swlat . ')';
            } else {
                $where[] = ' (m.gmlng >= ' . $swlng . ' OR m.gmlng <= ' . $nelng . ')';
                $where[] = ' (m.gmlat <= ' . $nelat . ' AND m.gmlat >= ' . $swlat . ')';
            }

This works really good for some zoom levels - I can move around - cross the dateline and I'll always get the right results. But when I really zoom out like in the image that I've attached in my first post - you can see that we have 2 datelines. My query should actually search for results between  0 and +180 and between -180 and 0 - since we see the whole world.

But in fact what I search for is for results like this ' (m.gmlng >= ' . $swlng . ' OR m.gmlng <= ' . $nelng . ')' - and it doesn't return the whole world...

Is my thinking correct or am I missing something?

I know that this doesn't have to do anything with the maps API - it is more related to the server side processing, but you guys are waaaaay more experienced than I am and I'm grateful for any advise!

Thanks,
Daniel

Rossko

unread,
Feb 24, 2012, 7:17:36 AM2/24/12
to Google Maps JavaScript API v3
> This works really good for some zoom levels - I can move around - cross the
> dateline and I'll always get the right results. But when I really zoom out
> like in the image that I've attached in my first post - you can see that we
> have 2 datelines. My query should actually search for results between  0
> and +180 and between -180 and 0 - since we see the whole world.

You'll have to detect this artificial condition,and code for what you
want. You might test the zoom level, or probably better, see if the
span of the map is greater than 360. If it is, then any bounds values
are ambiguous. But a simple forced -180 to +180 query will return
relevant results. You could do this client-side. You might need to
think about something similar for latitudes too.

THE_AI

unread,
Feb 24, 2012, 10:58:18 AM2/24/12
to google-map...@googlegroups.com
Zoom level is not an option for me, because the user can actually make the map's div smaller or bigger and in such a case I will have wrong data to work with.

What is a the span of the map? Do you mean the toSpan() function for the boundaries object?
http://code.google.com/apis/maps/documentation/javascript/reference.html#LatLngBounds

Can you perhaps point me to more documentation about that?
I don't understand the sense of this sentence: "Converts the given map bounds to a lat/lng span." and by looking at the output in the console I also can't understand how to use the values of the toSpan function?


Rossko

unread,
Feb 24, 2012, 12:44:01 PM2/24/12
to Google Maps JavaScript API v3
> I don't understand the sense of this sentence: "Converts the given map
> bounds to a lat/lng span."

You give it a bounds object, it tells you the "width" of that bounds
in degrees. Example : from -10 to +30 is a span of 40
from +30 to -10 is a span of 320

I do not think it will give consistent results for your purpose, from
map bounds. After all, a map spanning more than 360 degrees is
technically nonsense, but that is what you are trying to detect. I
certainly can't see it being able to distinguish if there are two or
three worlds in view, but I suppose you don't care about that really -
only if > 1 world's worth.

You may need to have code that calculates span from current zoom (to
derive degrees/pixel info) and current map size in pixels. That
would be capable of widths > 360 which you could detect and then
substitute a default "one world size" query.

Etienne Dethoor

unread,
Feb 24, 2012, 3:23:32 AM2/24/12
to Google Maps JavaScript API v3
I think your problem is related to the bug of google maps :
http://code.google.com/p/gmaps-api-issues/issues/detail?id=3650

On 23 fév, 21:16, Rossko <ros...@culzean.clara.co.uk> wrote:
> > but when I'm zoomed out I can see the whole map of the world in front of
> > me, but the boundaries for east and west are stating -79 east and +134
> > west.
>
> Example discussion from a few years backhttp://groups.google.com/group/google-maps-api/browse_thread/thread/d...

THE_AI

unread,
Feb 25, 2012, 4:21:37 AM2/25/12
to google-map...@googlegroups.com
@Rossko - I don't think that I can use the span. The div that contains the map can change - it can be 500px , 1000px, 2000px and the span can't really give me accurate results. Sometimes - I see the whole world and the span is around 290, sometimes I see the whorld 3 times and the span is 140. And sometimes I don't the world, but the span is again 140...

I tried to trick it with intersects . I thought that if I put a bound for the 0 meridian and I check if my bounds are intersecting it and if the east degree is negative, then I most probably see the whole world, but that is not the case. The boundary returns true for intersects only when I have a positive degree for the east value. The minute I get negative values for east the map tells me that the bounds are not intersecting the meridian.

@Etienne - well, I certainly expect the bound to return a bound that contains the whole world, but I don't know if this is a bug or not. I mean - the bounds function returns the coordinates properly - I mean the most right point is ... and the most left point is ... It returns the values that it should return, but not the values that we expect and see on the screen. Maybe something needs to be changed, I don't know. The maps API devs should step in to tell us  :)

Rossko

unread,
Feb 25, 2012, 6:13:51 AM2/25/12
to Google Maps JavaScript API v3
> @Rossko - I don't think that I can use the span. The div that contains the
> map can change - it can be 500px , 1000px, 2000px and the span can't really
> give me accurate results.

So you'd either have to do your calculation client-side, where you can
determine the current div size, or transmit that information to
wherever you do your calculation. There is no other way to guess.

> Sometimes - I see the whole world and the span is
> around 290, sometimes I see the whorld 3 times and the span is 140. And
> sometimes I don't the world, but the span is again 140...

Yup. There would always be debate about what the span "should" be.
If you can see two worlds, is the span 720? But that's nonsense, since
there is only one real world whose span is 360 ... Perhaps if you can
see more than world the span should limit at 360 ... but then it bears
no relation to what is actually onscreen .. and so on.
Whatever you say you want, someone else will have a use-case that
wants something different.

You want a particular solution from the possible choices, the reliable
way to get the answer is to calculate it yourself. Get the degrees
per pixel, count the pixels. Getting degrees/pixel requires knowledge
of zoom level and div size, which is only available client-side.
Reply all
Reply to author
Forward
0 new messages