{"action":"created","issue":{"url":"https://api.github.com/repos/alexreisner/geocoder/issues/892","labels_url":"https://api.github.com/repos/alexreisner/geocoder/issues/892/labels{/name}","comments_url":"https://api.github.com/repos/alexreisner/geocoder/issues/892/comments","events_url":"https://api.github.com/repos/alexreisner/geocoder/issues/892/events","html_url":"https://github.com/alexreisner/geocoder/issues/892","id":99187740,"number":892,"title":"When geocoding fails after updating an address the latitude / longitude remains","user":{"login":"fschwahn","id":57876,"avatar_url":"https://avatars.githubusercontent.com/u/57876?v=3","gravatar_id":"","url":"https://api.github.com/users/fschwahn","html_url":"https://github.com/fschwahn","followers_url":"https://api.github.com/users/fschwahn/followers","following_url":"https://api.github.com/users/fschwahn/following{/other_user}","gists_url":"https://api.github.com/users/fschwahn/gists{/gist_id}","starred_url":"https://api.github.com/users/fschwahn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fschwahn/subscriptions","organizations_url":"https://api.github.com/users/fschwahn/orgs","repos_url":"https://api.github.com/users/fschwahn/repos","events_url":"https://api.github.com/users/fschwahn/events{/privacy}","received_events_url":"https://api.github.com/users/fschwahn/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-08-05T11:54:48Z","updated_at":"2015-08-05T12:03:09Z","closed_at":null,"body":"Hi,\r\nI'm using geocoder with ActiveRecord, as follows:\r\n\r\n```ruby\r\nclass Address < ActiveRecord::Base\r\n  geocoded_by :full_address\r\n  after_validation :geocode, if: :full_address_changed?\r\n  ...\r\nend\r\n```\r\n\r\nWhen a valid address was entered in the past (and therefore latitude and longitude are set), and the address is changed to an invalid address (thus geocoding fails), the old latitude / longitude values remain. Is there any possibility to catch this and set latitude/longitude to nil when geocoding failed?\r\n\r\nAll the best,\r\nFabian"},"comment":{"url":"https://api.github.com/repos/alexreisner/geocoder/issues/comments/127973013","html_url":"https://github.com/alexreisner/geocoder/issues/892#issuecomment-127973013","issue_url":"https://api.github.com/repos/alexreisner/geocoder/issues/892","id":127973013,"user":{"login":"fschwahn","id":57876,"avatar_url":"https://avatars.githubusercontent.com/u/57876?v=3","gravatar_id":"","url":"https://api.github.com/users/fschwahn","html_url":"https://github.com/fschwahn","followers_url":"https://api.github.com/users/fschwahn/followers","following_url":"https://api.github.com/users/fschwahn/following{/other_user}","gists_url":"https://api.github.com/users/fschwahn/gists{/gist_id}","starred_url":"https://api.github.com/users/fschwahn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fschwahn/subscriptions","organizations_url":"https://api.github.com/users/fschwahn/orgs","repos_url":"https://api.github.com/users/fschwahn/repos","events_url":"https://api.github.com/users/fschwahn/events{/privacy}","received_events_url":"https://api.github.com/users/fschwahn/received_events","type":"User","site_admin":false},"created_at":"2015-08-05T12:03:09Z","updated_at":"2015-08-05T12:03:09Z","body":"For the record, I solved it as follows:\r\n\r\n```ruby\r\nclass Address < ActiveRecord::Base\r\n  geocoded_by :full_address\r\n  after_validation :geocode_or_reset_coordinates, if: :full_address_changed?\r\n  ...\r\n\r\n  private\r\n\r\n    def geocode_or_reset_coordinates\r\n      if geocode.nil?\r\n        self.latitude = nil\r\n        self.longitude = nil\r\n      end\r\n    end\r\nend\r\n\r\n```"}}