Suddenly getting “InvalidValueError: setComponentRestrictions: not an Object”?

Today I ran my specs and was surprised: What passed with a nice green message a few days ago now gave my javascript errors. RSpec informed me, that I had the following error somewhere in my GooglePlaces code:

InvalidValueError: setComponentRestrictions: not an Object

I use the fabulous geocomplete gem by @Ubilabs for my geocoding. It seems that Google changed something in their API, now requiring a country to be specified for geocoding, although their documentation still shows it as optional.

Luckily, the guys at Ubilabs are already aware of the problem and clearly show how to fix it. So when geocompleting, you simply have to add the “country” attribute:

$('.geocomplete').geocomplete({country: "US", type: ['(regions)']})

The “type” attribute was already mandatory before, I think. This should resolve the error.

To me and my application this poses a slightly bigger challenge, as I don’t have a country to state here. My customers are international and the bands tour international venues not always sticking to one country. I certainly want to continue to allow them to have concerts and tours through various countries. So what should I do? My first thoughts now are along the lines of identifying the location of the booker to at least keep it simple for smaller bands to find venues in their country. But that won’t work, if the booker sits in California and wants to enter a gig venue in Hongkong! Accessing the geolocation of the booker is also rather invasive to their privacy — and I value privacy a lot. So I think, I will have to make it more complicated for my customers and force them to enter a country first before they can enter a search string for a venue. That is sad and I don’t know why google does this. For now I will implement the country field and just hope that I misunderstood this API change and that we might still be able to simply search for a venue worldwide.

If you encountered this error, use the fix above if you can. If you have similar aches as mine with forcing us to ask for the country code first, please let me know.

Happy coding!

Btw if you or your team need help or want to get even better at Ruby on Rails and coding, check out this awesome guy, who offers his expertise. I worked with him and can whole-heartedly recommend him — we will change your code and coding forever.

Written by

Agile Coach, Business Innovator, Software Engineer, Musician

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store