Re: Integrate google maps: Cartographer v YM4R

The only explanation I can come up with is that you don't get any locations returned from you geosearch. Hence, you don't define the "conditions" variable. Then, you try to pass that nil variable to the :conditions parameter and it does not work. Are you getting any location back from your geosearch?

Re: Integrate google maps: Cartographer v YM4R

jo s wrote:

Do you know why graticule is not finding many locations(that do exist).  I am looking
for locations in Australia. For example

>>location = g.locate :region => "VIC", :country => "AUS", :locality => "Melbourne", :street => ""
=> #<Graticule::Location:0x4482c78 @precision=:unknown, @longitude=145.0, @latit
ude=-37.833302>

But if I add a "street" value it returns "location not found"

It looks like an issue with local search maps.  Look at the results for the queries:

http://geo.localsearchmaps.com/?state=V … =Melbourne
http://geo.localsearchmaps.com/?state=V … Queen%20St

Re: Integrate google maps: Cartographer v YM4R

I am getting results from my geo search. Also, i think we should consider splitting this topic into two: one for my issue and one for Jo s's, as they are indeed diffrent problems

Re: Integrate google maps: Cartographer v YM4R

Ahhah! Stupid me was using "@vehicles" instead of "@vehicle"
Still a problem though: Now its just not displaying any results.

If I say

conditions = "location_id in (1)"

it works, but if I say
conditions = "location_id in (#{@location.id})"

I get 0 results

Also, my console says that @location.id returns 27824910, or some other random number (It should return either 1, 2 or both). Thats why I get 0 results, but why does it return that?

location = Location.find(:all, :origin => '20904', :conditions => "distance < 10") in the console returns

[#<Location:0x3449834 @attributes={"city"=>"Silver Spring", "zip"=>"20904", "lng"=>"-76.9643", "id"=>"1", "phone"=>nil, "lat"=>"39.0704", "address"=>" Blue Valley Dr", "distance"=>"0.92157205055718", "state"=>"MD"}>]

Last edited by amoo3 (2007-07-02 18:15:02)

Re: Integrate google maps: Cartographer v YM4R

amoo3 wrote:

Also, my console says that @location.id returns 27824910, or some other random number (It should return either 1, 2 or both). Thats why I get 0 results, but why does it return that?

That seems really strange, indeed. I take it you do not have 27824910th row in your table? wink What do you get as output when you try to access other attributes of that result (like @location.name or so)? Perhaps you can see in the development log what is being returned? Also... make sure it is a single location that is returned and not a collection with only 1 item in it.

Regarding Jo s' problem: I am certain that this is the general internationalisation problem (like Brandon said already). I live in the UK and finding coordinates via the postcode seems not possible. At least not since the recent past if I am  right. I have not used any geosearch for a little while, but I think local search maps does get coordinates via the postcode in the UK now. When living in the US all these things seem to be no problem at all. Lucky them wink

Re: Integrate google maps: Cartographer v YM4R

Rudy, I've updated my previous post. Please look at it.

Thanks

Re: Integrate google maps: Cartographer v YM4R

Ok, solution for that:

@location_id = Array.new
    for location in @location
      @location_id << location.id
    end

Now, the problem is that this: #{@location_id} returns 13, no commas or spaces. How do I make it behave?


SOLVED!
Ok, I've managed to fix the problem and everything works now. Here how it looks:

def search
    @q = params[:q]
    @w = params[:where]
    @location = Location.find_within(10, :origin => @w)
    @location_id = Array.new
    x = @location.length
    y = 1
    for location in @location
      if y < x
        @location_id << "#{location.id}, "
      end
      if y>=x
       @location_id << "#{location.id}"
     end
     y = y+1
    end
    conditions = "location_id in (#{@location_id})" unless @location_id.empty?
    #@vehicle = Vehicle.find_by_contents @q
    @vehicle = Vehicle.find_by_contents( params[:q],
                     { },
                     { :conditions => conditions } )
    @hits = @vehicle.total_hits
    self.add_to_recent_searches
  end

Last edited by amoo3 (2007-07-03 00:31:41)

Re: Integrate google maps: Cartographer v YM4R

amoo3 wrote:

Ok, I've managed to fix the problem and everything works now. Here how it looks:

def search
    @q = params[:q]
    @w = params[:where]
    @location = Location.find_within(10, :origin => @w)
    @location_id = Array.new
    x = @location.length
    y = 1
    for location in @location
      if y < x
        @location_id << "#{location.id}, "
      end
      if y>=x
       @location_id << "#{location.id}"
     end
     y = y+1
    end
    conditions = "location_id in (#{@location_id})" unless @location_id.empty?
    #@vehicle = Vehicle.find_by_contents @q
    @vehicle = Vehicle.find_by_contents( params[:q],
                     { },
                     { :conditions => conditions } )
    @hits = @vehicle.total_hits
    self.add_to_recent_searches
  end

You can greatly simplify this:

@locations = Location.find_within(10, :origin => params[:where])
conditions = @locations.empty? ? nil : ["location_id in (?)", @locations]
@vehicle = Vehicle.find_by_contents(params[:q], :conditions => conditions)
@hits = @vehicle.total_hits
self.add_to_recent_searches

Re: Integrate google maps: Cartographer v YM4R

brandon wrote:

@locations = Location.find_within(10, :origin => params[:where])
conditions = @locations.empty? ? nil : ["location_id in (?)", @locations]
@vehicle = Vehicle.find_by_contents(params[:q], :conditions => conditions)
@hits = @vehicle.total_hits
self.add_to_recent_searches

Brandon, does your second line do the same thing as:

conditions = @locations.nil? ? nil : ["location_id in (?)", @locations.map(&:id)]

I guess one would not neet tp use "map" then? I am just wondering if I can improve my Ruby scripting smile

Re: Integrate google maps: Cartographer v YM4R

rudionrails wrote:

Brandon, does your second line do the same thing as:

conditions = @locations.nil? ? nil : ["location_id in (?)", @locations.map(&:id)]

I guess one would not neet tp use "map" then? I am just wondering if I can improve my Ruby scripting smile

ActiveRecord will automatically call .id on any ActiveRecord objects that are passed in as conditions.

Re: Integrate google maps: Cartographer v YM4R

One last thing: If I type in a location that is not found by GeoKit the app throws an error. How do catch the error and display a message myself?