0

I am using geocoder to get latitude and longitude from address

In model I added

class Clinic < ApplicationRecord
    geocoded_by :full_street_address
    after_validation :geocode

    def full_street_address
      [address_line1, city, state, country].compact.join(', ')
    end
end

and client has provided me addresses like this

{
    "name": "Bahrain Defence Force Royal Medical Services Hospital - Riffa",
    "address_line1": "West Riffa P O Box 28743",
    "country": "Bahrain",
    "state": "Al-Wusta",
    "city": "Riffa"
}

Now when I create a clinic its not returning latitude and longitude,

Seems that issue is with address and than with following line

[address_line1, city, state, country].compact.join(', ')

Is there a way I can specifically provide zipcode etc or how to handle above address?

Muhammad Faisal Iqbal
  • 1,796
  • 2
  • 20
  • 43

1 Answers1

0

Assuming that you followed the Geocoder documentation and added the longitude and latitude attributes to your model, I tried your code, you just need to add after_validation :geocode or use the method :geocode in any callback you want.

EDIT:

Okay so I think I didn't refresh the page by the time your question was updated, but I tried the exact same code and it worked as expected.

Bisher
  • 141
  • 6