Hi there,
I have an application built in Cake. It has a googlemaps search facility to search for billboards in suburb or a zipcode. The output should only be based on results within a certain area but it appears to be presenting a wider result set.
See here:
We have a db table called GeoData with a list of all suburbs/towns across the country with their lng and lat co-ordinates.
We have a db table call Locations with a list of all our billboard locations across the country with their lng and lat co-ordinates.
We have got the centre lng and lat from a query on our search value, then we create a bounding box around this to show the results:
$lat_diff = .35;
$lng_diff = .4;
$coords = array(
'lat_start' => ($data['GeoData']['lat'] - $lat_diff),
'lng_start' => ($data['GeoData']['lng'] - $lng_diff),
'lat_end' => ($data['GeoData']['lat'] + $lat_diff),
'lng_end' => ($data['GeoData']['lng'] + $lng_diff)
);
Next, we create a database query to search for records between these points, as follows:
$results = $this->Location->find('all', array(
'conditions' => array(
'AND' => array(
'Location.lat BETWEEN ? AND ?' => array($coords['lat_start'], $coords['lat_end']),
'Location.lng BETWEEN ? AND ?' => array($coords['lng_start'], $coords['lng_end'])
)
)
));
$results = (isset($results)) ? $results : array();
$this->set(compact('search', 'data', 'results', 'coords'));
The last parts of the function don't seem to be working correctly. Instead of presenting only a handful of results it seems to present all records within the state where the search values falls. E.g. if the state has 725 records it shows all of them whilst presenting the
Your assistance is most appreciated.
Regards, BillBixby
Googlemaps search for points in a database within an area
Moderator: General Moderators