0
votes

I'm trying to use Maps API from my mobile application in a similar manner as I can do using my Firefox browser:

http://maps.googleapis.com/maps/api/geocode/json?address=First Avenue New York Manhattan&sensor=true

Unfortunately, I always receive this error result: The 'sensor' parameter specified in the request must be set to either 'true' or 'false'

I tried TRUE, True, true... no way.

I also tried to use my API Key associated to my google account following this guide: https://developers.google.com/maps/documentation/javascript/tutorial?hl=it#api_key

In fact, I did:

http://maps.googleapis.com/maps/api/geocode/json?key={my_key}&address=First Avenue New York Manhattan&sensor=true

So, finally, I suppose my problems are related to the POST Request I prepared. This is the code I use for my Request:

request = new CIwHTTP; // The http pointer
const char* c1 = text.getCString(); // This is the string "address=First Avenue New York Manhattan&sensor=true"
int length = strlen(c1);
request->SetRequestHeader("Content-Type", "text/javascript; charset=utf-8"); 
request->Post("http://maps.googleapis.com/maps/api/geocode/json", c1, length, callback, NULL);

In the callback I got my result string, hopefully the JSON string coming from Google telling me the address list. I'm not so sure about the Header, but I changed few of them without results.

I use Marmalade, so my code is fully C++.

Could you help me?

1

1 Answers

1
votes

It seems Google doesn't like spaces in the address string and the call should be a GET call.

This is my working code:

CCString gURL = "http://maps.googleapis.com/maps/api/geocode/json?"; // URL base 
CCString *string_final = CCString::createWithFormat( (
        std::string(gURL.getCString()) + 
        std::string(text.getCString()) /* i.e. "address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false" */
        ).c_str() );  
request->Get(string_final->getCString(),callback, NULL);