我对 android Google 地图非常陌生一个地方请帮助我如何实现这一目标
问问题
149 次
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 回答