Page 1 of 1
Google Map API getting error [SOLVED]
Posted: Sat Sep 16, 2017 6:12 am
by proloy
My button code is below:
Code: Select all
on mouseUp
put the text of fld "city" into tCityName
put the text of fld "country" into tCountry
put the text of fld "vanue" into tVanue
//put "address=(& tVanue,& tCityName,& tCountry)" into tAddress
//put "&key=AIzaSyBmOIfVwbXdFd0_zFjz8kmHi5KqyJvjIKw" into appID
put "[https:]//maps.googleapis.[com]/maps/api/geocode/json?"&tAddress&appID into tURL
put URL tURL into tRawJSON
put textDecode(tRawJSON,"UTF8") into fld "weatherdata"
put arrayFromJson(tRawJSON) into tArray
end mouseUp
Result is below:
Code: Select all
{
"error_message" : "Invalid request. Missing the 'address', 'bounds', 'components', 'latlng' or 'place_id' parameter.",
"results" : [],
"status" : "INVALID_REQUEST"
}
Please advice
Re: Google Map API getting error
Posted: Sat Sep 16, 2017 2:25 pm
by Klaus
Hi proloy,
did you really comment out these two lines?
If not, you are passing the STRINGS tCityName etc. and not the content of the variables with that name to the URL function!
Code: Select all
put "address=(& tVanue,& tCityName,& tCountry)" into tAddress
## tAddress = address=(& tVanue,& tCityName,& tCountry)
Should be:
Code: Select all
put "address=(&" & tVanue & ",&" & tCityName & ",&" & tCountry & ")" into tAddress
And you are still not using
JSONtoArray(), we already had this two days ago!
viewtopic.php?f=7&t=29757
Best
Klaus
Re: Google Map API getting error
Posted: Sun Sep 17, 2017 2:54 am
by proloy
I have tried it out, but no luck
Code: Select all
on mouseUp
put the text of fld "city" into tCityName
put the text of fld "country" into tCountry
put the text of fld "vanue" into tVanue
//put "address=(&" & tVanue & ",&" & tCityName & ",&" & tCountry & ")" into tAddress
## tAddress = address=(& tVanue,& tCityName,& tCountry)
//put "&key=AIzaSyBmOIfVwbXdFd0_zFjz8kmHi5KqyJvjIKw" into appID
put "[https:]//maps.googleapis.[com]/maps/api/geocode/json?"& tAddress& appID into tURL
put URL tURL into tRawJSON
put textDecode(tRawJSON,"UTF8") into fld "weatherdata"
##put arrayFromJson(tRawJSON) into tArray
put JSONtoArray(tRawJSON) into tArray
end mouseUp
Same Result..
Re: Google Map API getting error
Posted: Sun Sep 17, 2017 6:12 am
by proloy
I figure out my problem,
My text fld is not working in tURL
my text fld is like:
Code: Select all
1600 Amphitheatre Parkway, Mountain View, CA
and google need like:
Code: Select all
1600+Amphitheatre+Parkway,+Mountain+View,+CA
if i write like this:
Code: Select all
[https]://maps.googleapis.[com]/maps/api/geocode/json?address=&tVanue&key=AIzaSyBmOIfVwbXdFd0_zFjz8kmHi5KqyJvjIKw
then location show "Sweet Fern Lane , Rhode Island , United States.
if i don't put &tVanue in url, then result is same.
please advice
Plz advice.
Re: Google Map API getting error
Posted: Sun Sep 17, 2017 8:36 am
by SparkOut
So you need to replace space with "+" in tAddress
Do you think you can figure out the syntax for that?
Better though is to urlEncode tAddress which will take care of any chars not valid for a url without having to make multiple replace statements.
BUT remember to concatenate the url string properly. LiveCode does not work to evaluate the contents of a variable inside the quoted literal string like php. Connect the parts together as shown above by Klaus
Re: Google Map API getting error
Posted: Sun Sep 17, 2017 8:55 am
by proloy
SparkOut wrote:So you need to replace space with "+" in tAddress
Do you think you can figure out the syntax for that?
Better though is to urlEncode tAddress which will take care of any chars not valid for a url without having to make multiple replace statements.
BUT remember to concatenate the url string properly. LiveCode does not work to evaluate the contents of a variable inside the quoted literal string like php. Connect the parts together as shown above by Klaus
SparkOut Thanks for your reply. i am compliantly new in coding, can you advice me how to do that

Re: Google Map API getting error
Posted: Sun Sep 17, 2017 12:21 pm
by SparkOut
You need to look up "replace" in the dictionary. The syntax is literally as I wrote above.
Also look up "urlEncode"
Klaus showed the way to make a string that combines quoted litrral text with variables.
Your best bet is to get some more practice by working through these simple instructional stacks
http://www.hyperactivesw.com/revscriptc ... ences.html
Re: Google Map API getting error
Posted: Mon Sep 18, 2017 5:23 am
by proloy
I have tried urlEncode:
Code: Select all
put urlEncode("tVanue") into tURL
maps/api/geocode/json?address=tVanue&key=
results:
Code: Select all
{
"results" : [],
"status" : "ZERO_RESULTS"
}
or
Code: Select all
replace "<tAdd>" with urlEncode(tVanue) in tURL
or
replace "<tAdd>" with urlEncode("tVanue") in tURL
maps/api/geocode/json?address=<tAdd>&key=
Code: Select all
"results" : [
{
"address_components" : [
{
"long_name" : "125",
"short_name" : "125",
"types" : [ "street_number" ]
},
{
"long_name" : "East Forrest Avenue",
"short_name" : "E Forrest Ave",
"types" : [ "route" ]
Re: Google Map API getting error
Posted: Mon Sep 18, 2017 10:10 am
by Klaus
Hi proloy,
as explained in my first post, you are urlencodeing the STRING "tVanue" and not the content of the variable with that name!
Code: Select all
...
## put urlEncode("tVanue") into tURL
put urlEncode(tVanue) into tURL
...
See the difference?
Putting quotes around a variable name makes it a STRING!
Best
Klaus
Re: Google Map API getting error
Posted: Tue Sep 19, 2017 7:43 am
by proloy
kalus, i have tried this:
Code: Select all
on mouseUp
##put the text of fld "vanue" into tVanue
## put urlEncode("tVanue") into tURL
put "[https:]//maps.googleapis.[com]/maps/api/geocode/json?address=&tVanue&key=AIzaSyBmOIfVwbXdFd0_zFjz8kmHi5KqyJvjIKw" into tURL
put URL tURL into tRawJSON
put textDecode(tRawJSON,"UTF8") into fld "weatherdata"
##put arrayFromJson(tRawJSON) into tArray
put JSONtoArray(tRawJSON) into tArray
end mouseUp
can you try this, and advice me..
Thanks.
Re: Google Map API getting error
Posted: Tue Sep 19, 2017 3:00 pm
by Klaus
Don't you read the postings here? I already explained your error twice...
OK, try this:
Code: Select all
on mouseUp
put urlencode(the text of fld "city") into tCityName
put urlencode(the text of fld "country") into tCountry
put urlencode(the text of fld "vanue") into tVanue
put "address=(&" & tVanue & ",&" & tCityName & ",&" & tCountry & ")" into tAddress
put "&key=AIzaSyBmOIfVwbXdFd0_zFjz8kmHi5KqyJvjIKw" into appID
put "https://maps.googleapis.com/maps/api/geocode/json?"& tAddress & appID into tURL
put URL tURL into tRawJSON
put textDecode(tRawJSON,"UTF8") into fld "weatherdata"
put JSONtoArray(tRawJSON) into tArray
end mouseUp
Re: Google Map API getting error
Posted: Tue Sep 19, 2017 5:02 pm
by SparkOut
Please, use the link I posted above and work through the samples to get more understanding of LiveCode basics.
Link repeated:
http://www.hyperactivesw.com/revscriptc ... ences.html
Re: Google Map API getting error
Posted: Wed Sep 20, 2017 8:35 am
by proloy
Life is simple, if you know
Like:
I am totally fresh in coding, i have no idea about it (That's why i don't understand your technical langues). But i start a project for sports broadcasting application
Every day i learn and apply on my project. After 4 days, finally i fixed my problem (Google Map API getting error) with your help and support.
Thank you very much both of you ( Klaus, SparkOut) to teach me.
Klaus i try your code, result:
Code: Select all
{
"results" : [],
"status" : "ZERO_RESULTS"
}
My quarry is not finish, tomorrow i will be back with new quarry. Let me try first

Re: Google Map API getting error
Posted: Wed Sep 20, 2017 10:02 am
by Klaus
proloy wrote:...
Klaus i try your code, result:
Code: Select all
{
"results" : [],
"status" : "ZERO_RESULTS"
}
So at least the format of the query is correct, and that was my intention.
I have no idea how exactly the Google API works, so that may be the problem here.
Re: Google Map API getting error
Posted: Wed Sep 20, 2017 9:29 pm
by jacque
I am totally fresh in coding, i have no idea about it (That's why i don't understand your technical langues).
Yes, there's a lot to learn if you aren't familiar with the jargon. I do think the link that SparkOut posted would help a lot and it would clear up much of the confusion. These are a series of stacks aimed at the new beginner who knows nothing about LC and they don't assume anything. It's a basic intro about the main concepts you have to know to get anything done.
For this one instance, do you know what a "string" is? It means a literal series of characters. Anything inside quotation marks is assumed to be that exact sequence of letters. So there is a big difference between these two things:
tVanue -- a variable that contains some kind of content
"tVanue" -- the literal letters t-V-a-n-u-e
In your handler:
Code: Select all
put "[https:]//maps.googleapis.[com]/maps/api/geocode/json?address=&tVanue&key=AIzaSyBmOIfVwbXdFd0_zFjz8kmHi5KqyJvjIKw" into tURL
The variable tVanue is inside a quoted string, which means that Google will receive the word "vanue" instead of the content the variable contains. So you must split that out of the quoted literal by using the example Klaus posted. It ends the quotation marks just before the variable, concatenates it using ampersands, and then starts the literal quote again.
Make sense?