0

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;

}

4

1 に答える 1

0

1-よくわかりませんが、http 接続はループしてはいけません

2- mSB を作成しましたが、使用していません

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
于 2012-06-14T10:27:15.500 に答える