Search code examples
androidgoogle-mapslocationsearchview

android- How to impaneled a searchview for map with String and Lat lang?


I want to have a searchview for my map that is based on the name of and the Latlang of the location.

I have a Hashmap();

but this line: map.put(BaseColumns._ID, "rowid AS " + BaseColumns._ID);

gives the error: Wrong 2nd argument type, required String, Found Latlang.

I tried to change the BaseColumns._ID to Latlang but I couldn't.

How can I fix this?

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;
}

Solution

  • You are declaring the map as:

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

    However, your data are strings:

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

    I suggest you declare the map like this:

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

    Or make sure your values are actually LatLng:

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