0

私はAndroidのGoogleマップに非常に慣れていません。ユーザーがプログラムの編集テキストをクリックするたびに、Googleマップの場所に自動提案を提供したいと思います。ユーザーが選択できるように、編集テキストにHを入力すると、対応するH関連の場所が表示されます。 1つの場所で私を助けてくださいどうすればこれを達成できますか

4

1 に答える 1

0

このコードは私のアプリで実行されています:

主な活動 :-

mAtv_DestinationLocaiton = (AutoCompleteTextView) findViewById(R.id.et_govia_destination_location);

mAtv_DestinationLocaiton.addTextChangedListener(new TextWatcher() {

            public void onTextChanged(CharSequence s, int start, int before,
                    int count) {
                Log.i("Count", "" + count);
                if (!mAtv_DestinationLocaiton.isPerformingCompletion()) {
                    autocompletePlaceList.clear();
                    DestiClick2 = false;
                    new loadDestinationDropList().execute(s.toString());
                }
            }
            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {
                // TODO Auto-generated method stub
            }
            public void afterTextChanged(Editable s) {
                // TODO Auto-generated method stub
            }
        });
    }

    private class loadDestinationDropList extends
            AsyncTask<String, Void, ArrayList<String>> {
        @Override
        protected void onPreExecute() {
            // Showing progress dialog before sending http request
            destinationProgBar.setVisibility(View.VISIBLE);
        }

        protected ArrayList<String> doInBackground(String... unused) {

            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            autocompletePlaceList = httpHelper
                    .getAutocompletePlaces(mAtv_DestinationLocaiton.getText()
                            .toString());

            return autocompletePlaceList;
        }

HttpHelperクラス:-

public class HttpHelper {
    HttpManager httpCall;
    private static final String TAG = "GooglePlacesApi";
    private Context mContext;

    public HttpHelper(Context context) {

        mContext = context;
        httpCall = new HttpManager();
    }


        public ArrayList<String> getAutocompletePlaces(String placeName) {
        String response2 = "";
        ArrayList<String> autocompletPlaceList = new ArrayList<String>();
        String url = Constants.GOOGLE_PLACE_AUTOCOMPLETE_URL + "input="
                + placeName + "&sensor=false&key="
                + Constants.GOOGLE_PLACE_API_KEY;
        Log.e("MyAutocompleteURL", "" + url);

        try {
            response2 = httpCall.connectToGoogleServer(url);
            JSONObject jsonObj = (JSONObject) new JSONTokener(response2.trim()
                    .toString()).nextValue();
            JSONArray results = (JSONArray) jsonObj.getJSONArray("predictions");

            for (int i = 0; i < results.length(); i++) {
                Log.e("RESULTS",
                        "" + results.getJSONObject(i).getString("description"));
                autocompletPlaceList.add(results.getJSONObject(i).getString(
                        "description"));
            }

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return autocompletPlaceList;
    }
    }
于 2012-11-01T09:38:01.550 に答える