2014-02-07 35 views
0

我想要使用Google地圖API從我的移動應用程序以類似的方式,我可以用我的Firefox瀏覽器做:使用谷歌地圖API - 傳感器true或false REQUEST_DENIED

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

不幸的是,我總是收到此錯誤結果:The 'sensor' parameter specified in the request must be set to either 'true' or 'false'

我試過TRUE,True,true ......沒辦法。

我還試圖用這個指南關聯到我的谷歌帳戶我的API密鑰:https://developers.google.com/maps/documentation/javascript/tutorial?hl=it#api_key

其實,我所做的:

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

所以,最後,我想我的問題是與我準備的POST請求相關。 這是我用我的請求代碼:

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); 

在我得到了我的結果字符串,希望JSON字符串從谷歌來告訴我地址​​列表中的回調。我對標題不是很確定,但是我改變了其中一些沒有結果。

我使用Marmalade,所以我的代碼完全是C++。

你能幫我嗎?

回答

1

看起來Google不喜歡地址字符串中的空格,並且該調用應該是GET調用。

這是我的工作代碼:

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);