2015-11-04 64 views
0

我想效仿Google Maps的“最近搜索”功能。Android - 从Places API获取最近的搜索结果

具体来说,我有一个AutoCompleteTextView与Google Places API挂钩。如果用户关注AutoCompleteTextView(阈值0),我想返回两个最近的搜索并可以选择搜索所有最近的搜索。

我查看了文档,找不到返回最近历史记录的公共方法。这是我必须存储在我自己的Web服务和手动检索?还是Google向公众提供这样的东西?

回答

2

可以存储最近搜寻的位置由textview获取文本并将其存储在共享的偏好或数据库。我建议共享偏好though.Then在偏好上AutoCompleteTextview

设定值显示建议:

SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE); 
String restoredText = prefs.getString("text", null); 
if (restoredText != null) { 
    String name = prefs.getString("name", "No name defined");//"No name defined" is the default value. 
    int idName = prefs.getInt("idName", 0); //0 is the default value. 
} 

你可以看看:

// MY_PREFS_NAME - a static String variable like: 
//public static final String MY_PREFS_NAME = "MyPrefsFile"; 
SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit(); 
editor.putString("name", "Elena"); 
editor.putInt("idName", 12); 
editor.commit(); 

从偏好数据检索这里:

http://systemout.net/2014/12/19/android-autocomplete-edittext-with-history/

+0

谢谢你的回答。据您所知,有什么方法可以从Google检索您的搜索?我试图避免在我的结尾存储搜索(如果可能)。如果我这样做了,我肯定会使用外部服务器进行存储,因为共享prefs文件对于我的用户执行的搜索量非常大。 –

+0

我怀疑API是否有一种方法,我已经找到了。 虽然你可以限制没有。的建议以编程方式保存在共享偏好或数据库中。 –

+0

很好,谢谢你的帮助。 –

相关问题