1

The Scenario

I have a few locations that I need to mark on the map. I can simply do this by marking everything at once, but since the number of locations that I need to mark will be huge, I want to handle it like this - When the users browse through the map, only the locations that are in the current view port will be Marked on the Map. Now, I can get the NE and SW bounds of the map using the getNorthEast() and getSouthWest() functions of the google.maps.LatLngBounds class. We can use the contains() function to find out if a location is in the view port, but again, since the number of location is large, it will slow down the browser, So i am planning to do it in the backend using Ajax.

I am planning to hit Ajax using the idle event listener and pass in the NE and SW co-ordinates and in the backend, find the locations that are within that bound and send it to the front end to display on the map.

The Problem

I am using PHP in the backend and MySQL as Database, how do I find if a given co-ordinate is within the rectangle that is formed by the co-ordinates(NE co-ordinate of the viewport and SW co-ordinate of the viewport) that I have provided?

Parthapratim Neog
  • 4,352
  • 6
  • 43
  • 79
  • 2
    see http://stackoverflow.com/questions/4834772/get-all-records-from-mysql-database-that-are-within-google-maps-getbounds – duncan Nov 03 '15 at 09:05
  • @duncan Hello, I implemented it from one of the answers, by @sergio where he uses this query `SELECT * FROM tilistings WHERE (a < c AND lat BETWEEN a AND c) OR (c < a AND lat BETWEEN c AND a) AND (b < d AND lng BETWEEN b AND d) OR (d < b AND lng BETWEEN d AND b)` ... its working fine when we are zoomed out, but when we are zoomed in, to precise location, the result is not precise. i.e. We still get the same search result if the viewport is showing a location close to the said location. I hope you get it – Parthapratim Neog Nov 03 '15 at 13:20
  • @duncan Nvm, its working now, he made a minor mistake with Brackets after `WHERE` – Parthapratim Neog Nov 03 '15 at 13:35

0 Answers0