I want to create a Polygon in Google Maps with Coordinates out of my SQLite Database. My Code can already create multiple Markers with Coordinates out of my Database. The Database contains an ID, E-Coordinates and N-Coordinates. I tried it with a Query like I did it with the markers but it wont work :/ Can somebody help me to solve this problem? (The Code below is working 100%) Thanks for the help!
Database:
// This is only a part of the database
public class DBHelper extends SQLiteOpenHelper {
public static final String KEY_ID = "key_id";
public static final String KEY_E_COORDINATES = "e_coordinates";
public static final String KEY_N_COORDINATES = "n_coordinates";
public DBHelper(Context context) {super(context, DATABASE_NAME, null,DATABASE_VERSION);}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_FINDS + "("
+ KEY_ID + " text, "
+ KEY_E_COORDINATES + " text, "
+ KEY_N_COORDINATES + " text, "
+ ")");
MapsActivity:
public class MapsActivity extends AppCompatActivity implements OnMapReadyCallback {
private GoogleMap mMap;
ArrayList<String[]> IDs = new ArrayList<String[]>();
DBHelper dbHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_map);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
dbHelper = new DBHelper(mapFragment.getContext());
String[] columns = {DBHelper.KEY_AREA};
SQLiteDatabase database = dbHelper.getWritableDatabase(); //SQLiteDB
ContentValues contentValues = new ContentValues();
String selectQuery = "SELECT key_id,e_coordinates,n_coordinates FROM finds ";
// Select the Coordinates with IDs from the Table and save it in tmp
Cursor cursor = database.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do {
String[] tmp = new String[3];
tmp[0] = cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.KEY_E_COORDINATES));
tmp[1] = cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.KEY_N_COORDINATES));
tmp[2] = cursor.getString(cursor.getColumnIndexOrThrow(DBHelper.KEY_ID));
IDs.add(tmp);
}
while (cursor.moveToNext());
} else
Log.d("mLog", "0 rows");
cursor.close();
}
@Override
public void onMapReady(GoogleMap googleMap) {
// Place the Markers on the Map
for (String[] pos : IDs) {
LatLng tmp = new LatLng(Double.parseDouble(pos[0]), Double.parseDouble(pos[1]));
googleMap.addMarker(new MarkerOptions().position(tmp).title("ID:" + pos[2]).icon(BitmapDescriptorFactory.defaultMarker(new Random().nextInt(360))));
googleMap.moveCamera(CameraUpdateFactory.newLatLng(tmp));
googleMap.moveCamera(CameraUpdateFactory.zoomTo(17.0f));
}
}
}