简体   繁体   中英

Best way to manage my own paths in Google Maps Android API

I have to do a mobile application which will have my own paths that i have to put in the map, what is the best way to manage the paths? KML files with the paths and upload them to the map or a specific database for that purpose?

Well, I'm using a simple SQLite database for that and it works fine, first I save the locations as real types in the database and then I can save the locations on a list of LatLgn objects or on a hashmap with String key and Marker object, for example:

private void getLatLgns() {

    DBConnection dbc = new DBConnection(this, "MapsDB", null, 1); 
    SQLiteDatabase db = dbc.getWritableDatabase();

    Cursor c = db.rawQuery("SELECT Latitude,Longitude from Records", null);
    if(c.moveToFirst()){ 
        do {
            allLatLng.add(new LatLng(Double.parseDouble(c.getString(0)), Double.parseDouble(c.getString(1))));
        }while (c.moveToNext());
    }
    db.close();
}    

private void addingMarkers {

for (int x= 0; x < allLatLng.size() ; x++) {
        hashMarkers.put(String.valueOf(x), mMap.addMarker(new MarkerOptions()
                .position(allLatLng.get(x)));
        Log.d("Position:", x + " " + allLatLng.get(x).latitude + " " + allLatLng.get(x).longitude);
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM