Android 在安卓系统中,如何区分同一位置上的标记?
我正在使用Android 在安卓系统中,如何区分同一位置上的标记?,android,google-maps,Android,Google Maps,我正在使用googlemaps在地图上添加标记。我的位置坐标,即LatLng值存储在SQLite数据库中。我可以添加标记到它们。但我的问题是,当两个标记位于完全相同的位置或LatLng只有一个对我可见时。我看不到另一个,否则我就碰了它们。所以请帮我区分同一位置的标记。我的代码是 private void viewAll() { addTollGate(); try{ String allQuery="select rowid _id,* from vehi
googlemaps
在地图上添加标记。我的位置坐标,即LatLng
值存储在SQLite
数据库中。我可以添加标记到它们。但我的问题是,当两个标记位于完全相同的位置或LatLng
只有一个对我可见时。我看不到另一个,否则我就碰了它们。所以请帮我区分同一位置的标记。我的代码是
private void viewAll() {
addTollGate();
try{
String allQuery="select rowid _id,* from vehiclesTable";
Cursor c4=db.rawQuery(allQuery,null);
if (c4.getCount()>0){
while (c4.moveToNext()){
strNumbers=c4.getString(c4.getColumnIndex("deviceNo"));
strVname=c4.getString(c4.getColumnIndex("vehicleName"));
try{
String strQuery="select rowid _id,* from logTable where _id=(select MAX(_id) from logTable where deviceNo='"+strNumbers+"')";
Cursor c5=db.rawQuery(strQuery,null);
if (c5.getCount()>0){
while (c5.moveToNext()) {
String allLatLng = c5.getString(c5.getColumnIndex("log"));
final String allDate = c5.getString(c5.getColumnIndex("date"));
String[] strArray1 = allLatLng.split(",");
double lat = Double.parseDouble(strArray1[0]);
double lng = Double.parseDouble(strArray1[1]);
String strTime = strArray1[2];
Date date = new Date(System.currentTimeMillis());
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
String dateToday = sdf.format(date);
Date oneHrBefore=new Date(System.currentTimeMillis()-3600*1000);
String strCurrent=dateToday+" "+strTime+":00";
SimpleDateFormat format=new SimpleDateFormat("dd-MMM-yyyy kk:mm:ss");
Date lastKnown=new Date();
try {
lastKnown=format.parse(strCurrent);
}catch (ParseException e){
e.printStackTrace();
}
if (dateToday.equals(allDate)) {
if (lastKnown.after(oneHrBefore)&&lastKnown.before(date)){
IconGenerator iconGenerator = new IconGenerator(this);
iconGenerator.setColor(getResources().getColor(R.color.myBlue1));
iconGenerator.setTextAppearance(R.style.iconGenText);
bmp = iconGenerator.makeIcon(strVname);
}else {
IconGenerator iconGenerator = new IconGenerator(this);
iconGenerator.setColor(getResources().getColor(R.color.myGreen));
iconGenerator.setTextAppearance(R.style.iconGenText);
bmp = iconGenerator.makeIcon(strVname);
}
} else{
IconGenerator iconGenerator = new IconGenerator(this);
iconGenerator.setColor(getResources().getColor(R.color.myRed));
iconGenerator.setTextAppearance(R.style.iconGenText);
bmp = iconGenerator.makeIcon(strVname);
}
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bmp);
markers = googleMap.addMarker(new MarkerOptions().position(new LatLng(lat, lng)).icon(bitmapDescriptor).title(strVname).snippet("Known @" + strTime + "," + allDate));
builder.include(new LatLng(lat, lng));
bounds = builder.build();
googleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0));
}
}
}catch (SQLiteException e){
e.printStackTrace();
}
}
}
}catch (SQLiteException e){
e.printStackTrace();
}
}
bitmapDescriptor:必须创建多个位图并在同一位置创建标记
markers = googleMap.addMarker(new MarkerOptions().position(new LatLng(lat, lng)).icon(bitmapDescriptor).title(strVname).snippet("Known @" + strTime + "," + allDate));