I have a page which allows users to search for their locations using the google maps API, and I want to be able to search for places I have stored in my DB that are close to the searched location.
So how can I query the DB on the fly and have the google map update?
here is my code for geocoding thus far:
function codeAddress(address) {
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
latLng = results[0].geometry.location;
map.setCenter(results[0].geometry.location);
result=results[0].address_components;
var info=[];
for(var i=0;i<result.length;++i)
{
if(result[i].types[0]=="administrative_area_level_1"){state = i.long_name; }
if(result[i].types[0]=="locality"){city = i.long_name;}
}
......
So how can I take those city and state variables and pass them to my controller to look for records?
EDIT - Im not using jquery on this page at all, the google maps API is plain ol' javascript.
I have zero AJAX knowledge, and very very little javascript knowledge.
So like, if I have the following variables: var state ="MD"
and var City = "Bethesda"
and my controller so far is:
def shops
@maps = Map.where("state LIKE ?", "%#{params[:state]}%" and "city LIKE ?", "%#{params[:city]}%")
end
And then I have to get that array back and loop through it all to display it.
And I have no idea how to do this, Ive seen numerous AJAX examples with rails but so far nothing has been particularly helpful..