perseverance
perseverance

Reputation: 6612

How do you get the postal_code using the Geocoder gem in Ruby on Rails?

I installed the GeoCoder gem for my Ruby on Rails project and am trying to get zip codes for the cities but the postal_code is always nil. All of the cities I've put in like San Jose, CA and Seattle, WA produce a nil for the postal_code.

I'm running these example queries in my rails console:

Geocoder.search("San Jose, CA").first.postal_code

A workaround I found was to run the following but it makes 2 calls which goes against the service quota:

Geocoder.search(Geocoder.search("Seattle, WA").first.coordinates).first.postal_code

Is there a better syntax to do this?

Thanks!

Upvotes: 2

Views: 1463

Answers (1)

Abhay Kumar
Abhay Kumar

Reputation: 1618

Try out this gem Area zip. It makes one call. you would do some thing like this to get the zip code

 "San Jose, CA".to_zip 

Upvotes: 2

Related Questions