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

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!

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

Related

Mediawiki API: Get image from articles in specific category

Without much success, I've been trying to retrieve images (and extracts) from all posts in a certain category.
Here's a query to get the images from the main page, but I haven't found a query for specific categories.
api.php?action=query&prop=images&titles=Main%20Page
Using search seemed more promising, but still it's not what I'm looking for.
api.php?action=query&list=search&format=jsonfm&srsearch=incategory:Marine_mammals
The second query could've been a good starting point if it provided page IDs.
What you want is to use the categorymembers generator, by adding &generator=categorymembers&gcmtitle=Category%3AMarine_mammals in place of &titles. Since I discovered generators I barely remember using the API for anything else. I'd also recommend sticking to mainspace. So for example,
https://en.wikipedia.org/w/api.php?action=query&prop=images&format=json&imlimit=10&generator=categorymembers&gcmtitle=Category%3AMarine_mammals&gcmnamespace=0&gcmlimit=50
Gives:
{"query-continue":{"images":{"imcontinue":"60257|Ursus_maritimus_4_1996-08-04.jpg"}},"query":{"pages":{"149269":{"pageid":149269,"ns":0,"title":"Blubber"},"19289045":{"pageid":19289045,"ns":0,"title":"Instituto Via Delphi"},"2178272":{"pageid":2178272,"ns":0,"title":"List of marine mammals of Australia"},"60257":{"pageid":60257,"ns":0,"title":"Marine mammal","images":[{"ns":6,"title":"File:Desmostylus2DB.jpg"},{"ns":6,"title":"File:Estuary-mouth.jpg"},{"ns":6,"title":"File:FL fig04.jpg"},{"ns":6,"title":"File:Humpback Whale underwater shot.jpg"},{"ns":6,"title":"File:Hydrurga leptonyx edit1.jpg"},{"ns":6,"title":"File:Maldivesfish2.jpg"},{"ns":6,"title":"File:Oceanic whale pump - journal.pone.0013255.g001.tiff"},{"ns":6,"title":"File:PikiWiki Israel 15217 Dolphin.JPG"},{"ns":6,"title":"File:Sea lion family.JPG"},{"ns":6,"title":"File:Sea otter cropped.jpg"}]},"36425597":{"pageid":36425597,"ns":0,"title":"Marine mammals as food"},"3703749":{"pageid":3703749,"ns":0,"title":"Marine otter"},"644379":{"pageid":644379,"ns":0,"title":"North Atlantic Marine Mammal Commission"},"1336536":{"pageid":1336536,"ns":0,"title":"Sea mink"},"567471":{"pageid":567471,"ns":0,"title":"Sea otter"},"2764345":{"pageid":2764345,"ns":0,"title":"United States Navy Marine Mammal Program"}}}}

Texticle in rails isn't providing the responses I want. How configurable is it? or have I got it wrong?

I'm using the texticle gem in a Rails 3 app.
I've got a table full of food names, such as Onion, Green Onion, Onion Powder, etc. etc.
I'm searching the table with
foodnames = FoodName.search(params[:search])
return render :json => foodnames
when I attempt to search for 'chopped onion', I had hoped to get back a list of matching 'onion', as those are somewhat close, but I'm getting an empty set.
If I use just 'Onion' or 'Onions', I get back the list I expected.
there seem to be conflicting documentation with texticle.
the github repository page, https://github.com/texticle/texticle shows methods like fuzzy_search, but when I try to run that I get undefined methodfuzzy_search' for #Class`
the other documentation http://texticle.github.com/texticle/ says nothing about fuzzy_search or similar capabilities.
my gem file has gem 'texticle', '~> 2.0', require: 'texticle/rails', though I did add that in and re-bundle install after I original had it without the version or require statements.
can anybody clarify what is going on here, and how I can get a better search result? It seems far too strict for my needs as is, and I suspect things are not working as they are supposed to.

Google Maps API Geocode Postal Code and set Country code?

I'm using this API call to Google Maps to get the latitude and longitude of a postal code
http://maps.googleapis.com/maps/api/geocode/json?address=2340&sensor=false
The postal code is in Australia. This API call returns locations all around the world with partial matching postal codes in the address.
Is there a parameter I can use to set the country to Australia?
Thanks
The correct way to do this is not via region biasing but rather using component filtering:
https://maps.google.com/maps/api/geocode/json
?components=country:AU|postal_code:2340
&sensor=false
Some demonstrations:
2340
93274
Please note that if you use the components parameter, you don't need to specify the address parameter.
The documentation says that Region Biasing is based on CcTLDs, which would make Australia au (haven't tried it myself).
Although it also states this:
Note that biasing only prefers results for a specific domain; if more relevant results exist outside of this domain, they may be included.

Missing routes in rails after using resource keyword

Not sure what the issue is here, but I have a basic line in my routes.rb:
resource :videos
But I don't see all the paths. Namely:
GET /videos/:id
I only see the following when running "rake routes":
videos POST /videos(.:format) videos#create
new_videos GET /videos/new(.:format) videos#new
edit_videos GET /videos/edit(.:format) videos#edit
GET /videos(.:format) videos#show
PUT /videos(.:format) videos#update
DELETE /videos(.:format) videos#destroy
What am I missing? Thanks!
You make videos a singular resource, but videos is a collection so you have to do :
resources :videos
http://guides.rubyonrails.org/routing.html#crud-verbs-and-actions
Change your line to resources :videos, and the missing route will magically appear

FourSquare API is giving lots of result but not the result I expect

I am using FourSquare api for searching a particular business
https://api.foursquare.com/v2/users/search?name=Spa Gregories&oauth_token=ACCESS_TOKEN
it is giving lots of result but not the result i expect. that is
Spa Gregories
2710 Via De La Valle, Ste B-270
San Diego, California 92014
when i use https://foursquare.com/search?q=Spa+Gregories&near=san+diago then i got the exact result. So is their any way to find the business according the location. I have only name and city location to use for Search. I have also checked for the venues option but it asks for longitude and latitude.
thnks
Seems you're hitting the user search endpoint instead of the venue search.
Looks like this is the one you want:
https://developer.foursquare.com/docs/venues/search.html