android-如何使用String和Lat lang对map的searchview进行拼接?

时间:2017-01-10 17:22:45

标签: android google-maps location searchview

我希望我的地图的搜索视图基于该地点的名称和Latlang。

我有一个Hashmap();

但这一行:   map.put(BaseColumns._ID," rowid AS" +                 BaseColumns._ID);

给出错误:错误的第二个参数类型,必需的字符串,找到Latlang。

我尝试将BaseColumns._ID更改为Latlang,但我无法做到。

我该如何解决这个问题?

private static final String TAG = "DictionaryDatabase";

//The columns we'll include in the dictionary table
public static final String KEY_WORD = SearchManager.SUGGEST_COLUMN_TEXT_1;
public static final Latlang KEY_DEFINITION = SearchManager.SUGGEST_COLUMN_TEXT_2;

private static final String DATABASE_NAME = "dictionary";
private static final String FTS_VIRTUAL_TABLE = "FTSdictionary";
private static final int DATABASE_VERSION = 2;

private final DictionaryOpenHelper mDatabaseOpenHelper;
private static final HashMap<String,Latlang> mColumnMap = buildColumnMap();

/**
 * Constructor
 * @param context The Context within which to work, used to create the DB
 */
public DictionaryDatabase(Context context) {
    mDatabaseOpenHelper = new DictionaryOpenHelper(context);
}

private static HashMap<String,Latlang> buildColumnMap() {
    HashMap<String,Latlang> map = new HashMap<String,Latlang>();
    map.put(KEY_WORD, KEY_DEFINITION);
    map.put(KEY_WORD, KEY_DEFINITION);
    map.put(BaseColumns._ID, "rowid AS " +
            BaseColumns._ID);
    map.put(SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID, "rowid AS " +
            SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID);
    map.put(SearchManager.SUGGEST_COLUMN_SHORTCUT_ID, "rowid AS " +
            SearchManager.SUGGEST_COLUMN_SHORTCUT_ID);
    return map;
}

1 个答案:

答案 0 :(得分:1)

您将地图声明为:

HashMap<String,Latlang> map = new HashMap<String,Latlang>();

但是,您的数据是字符串:

map.put(SearchManager.SUGGEST_COLUMN_SHORTCUT_ID, "rowid AS " +
            SearchManager.SUGGEST_COLUMN_SHORTCUT_ID);

我建议您像这样声明地图:

HashMap<String, String> map = new HashMap<String, String>();

或确保您的值实际上是LatLng:

map.put(BaseColumns._ID, new LatLng(latitude, longitude));