2012-04-22 68 views
1

我試圖通過http請求發送GPS數據。Android SDK。 HTTP POST雙變量

的問題是,GPS數據是雙格式和nameValuePair.add(new BasicNameValuePair(String, String)

不會允許雙重價值。

如何發送double值或將double轉換爲字符串?

感謝,

httpclient client = new defaulthttpclient(); 
httppost post = new httppost("web address"); 
post.setEntity(new UrlencodedFormEntity(nameValuePairs)); 
httpresponse response = client.execute(post); 

回答

1

您可能需要使用兩個namevaluepairs中分別發送經緯度:

double latitude = currentLocation.getLatitude(); 
double longitude = currentLocation.getLongitude(); 
nameValuePairs.add(new BasicNameValuePair("latitude",Double.toString(latitude))); 
nameValuePairs.add(new BasicNameValuePair("longitude",Double.toString(longitude))); 
+0

我不能用'的toString()'函數,因爲一顆靈長類動物的double類型的。我可以直接通過獲取請求發送雙倍數據嗎? get url應該能夠直接保存連接的變量。 – 2012-04-22 13:03:47

+0

對不起,我的錯誤,你可能會使用Double.toString(值),我會編輯答案來反映這一點。 – lenik 2012-04-22 13:17:19

+0

那麼簡單... – 2012-04-22 14:04:17