发送GPS数据到服务器
问题描述:
我做了一个GPS程序。我想将当前地址发送到服务器。我陷入了字符串部分。你能纠正它吗?我的代码是:发送GPS数据到服务器
try {
Geocoder mGC = new Geocoder(this, Locale.ENGLISH);
addresses = mGC.getFromLocation(mLocation.getLatitude(),
mLocation.getLongitude(), 1);
if (addresses != null) {
Address currentAddr = addresses.get(0);
StringBuilder mSB = new StringBuilder("Address:\n");
for (int i = 0; i < currentAddr.getMaxAddressLineIndex(); i++) {
mSB.append(currentAddr.getAddressLine(i)).append("\n");
String a=mSB.toString();
if(a!=null){
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(
"URL");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
1);
nameValuePairs.add(new BasicNameValuePair(
"data",a));
httppost.setEntity(new UrlEncodedFormEntity(
nameValuePairs));
HttpResponse response = httpclient
.execute(httppost);
Toast.makeText(getBaseContext(),
response.toString(),
Toast.LENGTH_LONG).show();
continue;
}
答
1不知道,但HTTP连接不应该是循环
2 - 创建的最高位,但不用于
StringBuilder mSB = new StringBuilder("Address:\n");
for (int i = 0; i < currentAddr.getMaxAddressLineIndex(); i++) {
mSB.append(currentAddr.getAddressLine(i)).append("\n");
} <----------------- loop should end here
String a= mSB.toString() ;<-------------------------- carete string from mSB
*我得到卡住*??你得到什么输出/错误? – GAMA
你为什么在循环中建立http连接? –
要求将地址转换为字符串 – user1437027