我想在谷歌地圖上顯示多個標記(可能爲100或更多)。我從sqlite的然後閱讀LAT和LNG我加入他們的谷歌地圖,但告訴我只是一個標記?Android - 谷歌地圖 - 如何在地圖上顯示多個標記?
我必須使用主題或AsyncTask?
這裏是我的代碼:
public class StartActivity extends AppCompatActivity implements OnMapReadyCallback {
private GoogleMap mMap;
public SQLiteDatabase sql;
public Cursor cursor;
Context context;
public static String PACKAGE_NAME;
ArrayList<LatLng> markerPoints;
LatLng newLatLng;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
// 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);
context = getApplicationContext();
DBS db = new DBS(context);
PACKAGE_NAME = context.getApplicationContext().getPackageName();
db.GetPackageName(PACKAGE_NAME);
db.CreateFile();
try {
db.CreateandOpenDataBase();
} catch (IOException e) {
e.printStackTrace();
}
sql = db.openDataBase();
try {
cursor = sql.rawQuery("SELECT _Lat,_Lng,_Date,_Time FROM Places where UserCode = 101", null);
if (cursor != null) {
if (cursor.moveToFirst()) {
do {
markerPoints = new ArrayList<LatLng>();
Structure_DB sdb = new Structure_DB();
sdb._Lat = cursor.getString(cursor.getColumnIndex("_Lat"));
sdb._Lng = cursor.getString(cursor.getColumnIndex("_Lng"));
sdb._Date = cursor.getString(cursor.getColumnIndex("_Date"));
sdb._Time = cursor.getString(cursor.getColumnIndex("_Time"));
newLatLng = new LatLng(Double.parseDouble(sdb._Lat), Double.parseDouble(sdb._Lng));
markerPoints.add(newLatLng);
} while (cursor.moveToNext());
}
}
} catch (Exception e) {
} finally {
cursor.close();
}
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
Iterator<LatLng> iterator = markerPoints.iterator();
while (iterator.hasNext()) {
MarkerOptions markerOptions = new MarkerOptions()
.position(iterator.next());
mMap.addMarker(markerOptions);
}
}
}
的可能的複製[如何顯示谷歌地圖API V2上MapFragment多個標記?](http://stackoverflow.com/questions/13855049/how-to-show-multiple-markers-on-mapfragment-in-google-map-api-v2) –