I recently implemented a map that needed to find points in a mysql  
database within X distance of a marker on the map... I ended up using  
sphinx (http://www.sphinxsearch.com) to perform the search for me and  
I was very pleased with the results.

http://www.keytosavannah.com/maps/search?l=8840%20Abercorn%20Street%20Savannah%20GA%2031419&r=.25

clicking that link will take you to the map and automatically place  
the center of the search at the address in the url with a quarter mile  
radius.  click the "Search" tab or drag the pin marker around if you  
want to play with the controls.

basically the process is something like this:
0) install & configure sphinx ;)
1) feed your mysql database rows to the sphinx indexer, specifying  
attributes for latitude & longitude.
2) use the API of your choice (php in my case) to have sphinx get your  
matching points.

sample code pasted from my app:

$cl = new SphinxClient();
$cl->SetServer("localhost", 3312);
$cl->SetLimits(0, 2000);
$cl->SetGeoAnchor('latitude', 'longitude', $latitude*pi()/180,  
$longitude*pi()/180);
$cl->SetFilterFloatRange('@geodist', 0.0, $distance*1609.344);
$result = $cl->Query("", 'listings');

'latitude' and 'longitude' are the names I gave my appropriately-named  
sphinx attributes
$latitude and $longitude are the variables holding the lat/long of my  
search center
$distance is in miles in this case due to the *1609.344, adjust  
accordingly
'listings' is the name of the sphinx index I'm searching
SetLimits(0,2000) is just to limit results to 2000 rows.

3) look at the sphinx results to find the ids of the matching rows.

$matching_ids = array();
foreach ( $result["matches"] as $doc => $docinfo ) {
        $matching_ids[] = "$doc";
}
$ids = implode(", ", $matching_ids);

4) grab those rows from your database and do whatever needs to be done  
with the data.

query to the effect of:
SELECT whatever FROM table WHERE id IN ($ids)

hope that helps somehow,
-Ty Wangsness

On Jun 10, 2009, at 3:40 PM, Andrew Leach wrote:

>
> On Jun 10, 8:10 pm, Dommer <[email protected]> wrote:
>> Okay, I see what you're saying here: take the centerpoints of all of
>> the polygons, and select out the ones that are east of some
>> easternmostpoint, west of some westermost point etc.  But how could I
>> get the easternmost and westernmost points...  I suppose I'll have to
>> do the calculation to figure out based on the original centerpoint...
>> Yeah, that's possible.
>
> I would suggest not using centre points, but rather the extreme
> points. I have a similar problem in an application of mine.
>
> I have a denormalised table containing the extents of the bounding
> rectangle of my regions, and I get the regions any part of whose
> bounding box lies within 0.0075deg of my reference point. I worked out
> that 0.0075deg is all I need. There are server-side formulae you can
> code to work out how many degrees 1000ft is at any particular
> latitude.
>
>  SELECT DISTINCT region_id FROM extents_table
>  WHERE minlon<$cx+0.0075
>    AND maxlon>$cx-0.0075
>    AND minlat<$cy+0.0075
>    AND maxlat>$cy-0.0075
>
> You could use a similar query but instead of using a circle around a
> reference point, use the viewport bounds.
>
> Having got the list of regions which are applicable, you then select
> those boundaries from your boundary-points table and draw the lines.
> You will be drawing regions which could lie some way away from the
> viewport, but then that allows some ability to pan around.
>
> If you don't want a denormalised table to speed things up, you could
> get the minlon variables by using group functions on the boundary-
> points table (which is how I populate the extents table):
>
>  select region_id,cc_code,min(lon),max(lon),min(lat),max(lat) from
> boundary_points
>  where region_id = '$r'
>  group by region_id;
>
> Andrew
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to