openstreetmaprails-geocoder

Large inaccuracies with Ruby Geocoder and/or OpenStreetMap


I'm using the geocoder gem in rails to get latitude & longitude for addresses and then display them in OpenStreetMap.

When I search for my old address:

>> results = Geocoder.search("1000 Mount Curve Ave E, Altadena, CA 91001")

I get:

>> results.first.coordinates
=> [34.1976645, -118.1278219]

Mount Curve Address Discrepancy

Those coordinates are perhaps a thousand feet off. (See image.) The resulting accurate coordinates from Google Maps are [34.200503,-118.1310407].

I've tried another address and it was much farther off, perhaps a mile. (1346 E Woodbury Rd, Pasadena, CA 91104)

I've tried yet another address, and it was pretty much dead-accurate. (922 E Brockton Ave, Redlands, CA 92374)

Does anyone know what might be causing these inaccuracies and how to get accurate results consistently?


Solution

  • Because of the inaccuracies and/or limitations with OSM/Nominatim, I switched to Google maps service. At the top of my controller I added:

    require 'google_maps_service'
    

    And in my controller's show routine I ended up with this, which yields accurate results:

    source = Property.find(params[:id])
    @property = PropertyDecorator.new(source)
    gmaps = GoogleMapsService::Client.new(key: '[removed, put in your own key here]')
    results = gmaps.geocode("#{@property.address1} #{@property.address2}")
    if results[0] == nil
      @lat = 0 
      @lng = 0 
    else
      @lat = results[0][:geometry][:location][:lat]
      @lng = results[0][:geometry][:location][:lng]
    end