Just a quick note: We’re getting some irregularities on the geocoding results for new events on the site. This takes the form of events showing up as “N CAROLINA” instead of “NC” for example. I think that this is due to a change in one of the geocoders that I am using. Or it could be Google geocoder failing and another geocoder returning their default value, I haven’t been able to dig that far into it.

In a nutshell, I use the very nice GeoKit rails plugin to handle all the geocoding for mtbcalendar.com. Geocoding allows me to take any address (like “Los Gatos, CA”) and returns latitude and longitude coordinates, which I can then easily overlay on the map. In addition to these coordinates, it also returns a bunch of other information like proper state. This allows me to fairly easily create the state and regional search pages (in addition to some tags).

This is the pertinent code:

  def try_to_geocode
    res = MultiGeocoder.geocode(self.location)
    if res.success
      self.lat = res.lat
      self.lng = res.lng
      if res.state.nil?
        # if google screws us by geocoding without giving us the state or province,
        # try to it geocode again with the lat, lng (basically reverse geocode lookup)
        res = MultiGeocoder.geocode([self.lat,self.lng])
        if res.success
          self.state = res.state
        end
      else
        self.state = res.state
      end
      self.state = abbr_state(self.state) if !self.state.nil? && self.state.length > 2
      self.region_id = identify_region_id(self.state,self.lat,self.lng) unless self.state.nil?
        end
  end

The line that I have had to add is line 16, which is basically a big, ugly case statement with “irregular” states.

Net/net on this: while I track down the issue (and write a fix), you’ll have to live with some poor searching. My apologies.

Tags: , , , ,

  • Nathan

    Did you ever track this down — I am experiencing the same issue. For me it seems non-deterministic. I can’t get that result to repeat with any of the geocoders our app is configured to failover to.

  • admin

    Nope, but it seems to have stopped about 1 week ago. I could also never track it down (my config tries Google Maps, then fails over to Yahoo!) or repeat it reliably.

blog comments powered by Disqus