Within my application I have a map and I'm showing markers on the map which represent objects that I get from the database. The objects have latitude and longitude. The objects are selected only if their latitude and longitude are within the boundaries of the map. To be precise, it's a Google Maps block with a map and on every drag/zoom I request the server for a list of new objects passing the 4 values of the map boundaries that I receive from the Google Map. In GMaps JS API it looks like this:

bounds = map.getBounds(); // Bounds of the map.
NE = bounds.getNorthEast(); // North East corner.
SW = bounds.getSouthWest(); // South West corner.

After that, on every event fired, I send a request to the server sending this data:

    'x_min': SW.lng(),
    'y_min': SW.lat(),
    'x_max': NE.lng(),
    'y_max': NE.lat(),

It is Django/Python on the server, so I handle the request like so:

polygon = Polygon.from_bbox((x_min, y_min, x_max, y_max))
queryset = queryset.filter(geo_location__contained=polygon)

Now, all of that works fine unless... the right side of the boundary is crossing the anti meridian. So, the left side is for example 90 and the right side is for example -170. In this case I obviously get no results on the map.

I'm pretty much sure that's a common problem, but can't find any viable solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.