I need to create a page that
- takes 2 addresses (to and from),
- plots the route AND areas within 1 mile of this route,
- THEN figure out if any of a predefined list of thousands of lat/long coords falls within this area (w/ 1 mile, along the route)
I'm using google-maps v3 api and the routeboxer class.
Here is a good example: http://google-maps-utility-library-v3.googlecode.com/svn/trunk/routeboxer/examples/routeboxer-v3.html
As you can see, #1 and #2 are basically taken care of by this routeboxer example.
My question is about handling #3 EFFICIENTLY. Routeboxer provides a series of box-coords (North East lat/long to South West lat/long corners). I can loop box by box and then loop within each of the predefined lat/long coords to see if any coord in the list falls within the area of the routeBoxes, but this is a lengthy, inefficient process.
I am looking for a means to optimize this (#3) search portion. Some ideas:
- a binary search; would require sorting the coord list by lat, then long - but would likely speed things up
- mySQL query: this takes processing off the usersPC and puts it onto our servers;
I would query for each routeBox:
select * from myListOfLatLongs where lat box_latwest && lng box)lngsouth
Which is more ideal for speed & stability? Are there any better ideas/opimizations? The bottom line is that without optimization, this can theoretically return MANY boxes, and each box would then need to be compared against thousands of coords -- which can become a lengthy process. Any help appreciated