
Chris
Staff

Sep 15, 2010, 2:17 PM
Post #18 of 19
(1907 views)
Shortcut
|
|
Re: [InHouse] Google Maps with Geocoding
[In reply to]
|
Can't Post
|
|
Hi InHouse, The geocoding plugin will take addresses (postal codes should work too) and turn them into (Lat,Lng) coordinates. That would be the first step in doing proximity searches. A proximity search is basically accomplished by defining a "minimum bounding rectangle" of (Lat,Lng) coords around your centre point (to quickly cull very distant locations.) If the Earth were perfectly flat, this would be as simple as: WHERE lat BETWEEN (<?php echo $record['lat'] - $dist ?> AND <?php echo $record['lat'] + $dist ?>) AND lng BETWEEN (<?php echo $record['lng'] - $dist ?> AND <?php echo $record['lng'] + $dist ?>) For better precision, you'll need to adjust your longitude delta depending on the latitude (since 1° of lng decreases from 111km to 0km as you approach a pole.) If you need to sort by distance and cull results which are farther than your max_dist (i.e. ones you caught with your rectangle but aren't in your circle,) you'll need to also use the Distance Formula (but for speed, skip the sqrt() part until you get your results back from MySQL.) In short, it's somewhat complicated to do right. We may include examples with the plugin, and if not, we're available to help out through consulting, which should be quick because we've done this before. :) I hope this helps! Chris
|