Title: BASH script for storing a Google geocode api lookup as a variable
Tags: bash;google-maps;curl;geolocation
Question: I am trying to store a Google geocode lookup as a variable in BASH.
Here's what I want to end up with
(or something similar to it)
_GEOINFO=$(curl "http://maps.googleapis.com/maps/api/geocode/json?address="$_WHERE""
Here's what almost works:
_CITY="Grand rapids"
_STATE="Michigan"
_COUNTRY="United States of America"
_WHERE="\"$_CITY\",\"$_STATE\",\"$_COUNTRY\""
curl "http://maps.googleapis.com/maps/api/geocode/json?address="$_WHERE""
Here's what doesn't:
curl "http://maps.googleapis.com/maps/api/geocode/json?address=$_WHERE"
I've tried so many different variations on escaaping:
\"$_WHERE\", \'\"$_WHERE\"\', \"${_WHERE}\",
For most things I've tried, I get an error saying:
parse error: Invalid numeric literal at line 1, column 10
Comment: By the way, if you do a search  like Toronto, Ontario, Canada it will work.  But for USA it doesn't.

Here is the accepted answer: FIXED IT!
# store location information into variables
_CITY="Grand rapids"
_STATE="Michigan"
_COUNTRY="United States of America"
# store all information as one string
_WHERE="$_CITY,$_STATE,$_COUNTRY"
# replace spaces with a +
_WHERE="${_WHERE// /+}"
# store the geo-location information into a variable
_GEOINFO=$(curl "http://maps.googleapis.com/maps/api/geocode/json?address=\"$_WHERE\""


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:04/08/16', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<bash><google-maps><curl><geolocation>', 'Title': 'BASH script for storing a Google geocode api lookup as a variable', 'ViewCount': 154, 'id': 36489353, 'user_AboutMe': '', 'user_AccountId': 2878717.0, 'user_DisplayName': 'user2470057', 'user_Reputation': 499.0, 'user_Views': 32.0, 'user_id': 2470057.0}}