为android谷歌地图提供自动建议
我是android Google maps的新手,我想在用户点击我程序中的编辑文本时在Google map places中提供自动建议。选择我在编辑文本中输入的H,相应的H相关位置显示,以便用户可以选择一个位置。请帮助我如何实现这一点此代码正在我的应用程序中运行: 主要活动:-为android谷歌地图提供自动建议,android,google-maps,search,google-places,Android,Google Maps,Search,Google Places,我是android Google maps的新手,我想在用户点击我程序中的编辑文本时在Google map places中提供自动建议。选择我在编辑文本中输入的H,相应的H相关位置显示,以便用户可以选择一个位置。请帮助我如何实现这一点此代码正在我的应用程序中运行: 主要活动:- mAtv_DestinationLocaiton = (AutoCompleteTextView) findViewById(R.id.et_govia_destination_location); mAtv_Dest
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;
}
mAtv_DestinationLocaiton=(AutoCompleteTextView)findViewById(R.id.et_govia_destination_location);
mAtv_DestinationLocaiton.addTextChangedListener(新的TextWatcher(){
public void onTextChanged(字符序列,int start,int before,
整数计数){
Log.i(“计数”,“计数+计数”);
如果(!mAtv_DestinationLocaiton.isPerformingCompletion()){
autocompletePlaceList.clear();
2=假;
新建loadDestinationDropList().execute(s.toString());
}
}
更改前的公共无效(字符序列、整数开始、整数计数、,
整数后){
//TODO自动生成的方法存根
}
公共无效后文本已更改(可编辑){
//TODO自动生成的方法存根
}
});
}
私有类loadDestinationDropList扩展
异步任务{
@凌驾
受保护的void onPreExecute(){
//发送http请求前显示进度对话框
destinationProgBar.setVisibility(View.VISIBLE);
}
受保护的ArrayList doInBackground(字符串…未使用){
试一试{
睡眠(3000);
}捕捉(中断异常e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
autocompletePlaceList=httpHelper
.getAutocompletePlaces(mAtv_DestinationLocaiton.getText()
.toString());
返回自动完成置换列表;
}
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;
}
}
公共类HttpHelper{
HttpManager-httpCall;
私有静态最终字符串标记=“GooglePlacesApi”;
私有上下文;
公共HttpHelper(上下文){
mContext=上下文;
httpCall=新的HttpManager();
}
公共ArrayList getAutocompletePlaces(字符串地名){
字符串响应2=“”;
ArrayList autocompletPlaceList=新建ArrayList();
字符串url=Constants.GOOGLE\u PLACE\u AUTOCOMPLETE\u url+“输入=”
+placeName+“&sensor=false&key=”
+Constants.GOOGLE\u PLACE\u API\u KEY;
Log.e(“MyAutocompleteURL”,即“+url”);
试一试{
response2=httpCall.connecttogogleserver(url);
JSONObject jsonObj=(JSONObject)新的JSONTokener(response2.trim()
.toString()).nextValue();
JSONArray结果=(JSONArray)jsonObj.getJSONArray(“预测”);
对于(int i=0;i
遵循此链接:我希望使用placematrix api显示位置?这里您使用任何jar文件连接http?不使用.jar文件,而是使用Google Direction api获取详细信息完成PlaceList这是什么?ArrayList autocompletePlaceList=new ArrayList();是用于存储自动压缩记录的Arraylist没有问题我删除了一些不必要的代码,所以只需在httphelper类中剪切自动压缩方法并粘贴主活动。然后使用direct。它很简单