我正试图在Android上使用GoogleMaps来区分标记。我尝试了StackOverflow上提供的几个解决方案。其中一个是为标记设置标记,在点击标记上我将检索该标记(取决于我点击的标记),事情是它没有区分并显示我目前两个标记的相同信息有
以下是代码的一部分:
private void markUserLocationMap(final Double currentUserLatitude, final Double currentUserLongitude) {
FirebaseFirestore db = FirebaseFirestore.getInstance();
db.collection("users").get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (DocumentSnapshot document : task.getResult()) {
Log.d(TAG, document.getId() + " => " + document.getData());
Map<String, Object> data = document.getData();
String s = data.get("location").toString();
List<String> userInfo = new ArrayList<String>();
final String username = data.get("username").toString();
userInfo.add(username);
final String teamName = data.get("teamName").toString();
userInfo.add(teamName);
String latitude = s.substring(s.indexOf("latitude") + 9, s.indexOf(","));
String longitude = s.substring(s.indexOf("longitude") + 10,s.indexOf("}"));
double latitudeValue = Double.parseDouble(latitude);
double longitudeValue = Double.parseDouble(longitude);
if(( (currentUserLatitude != latitudeValue)&& (currentUserLongitude != longitudeValue) ) && ((latitudeValue+1<=currentUserLatitude) ||(latitudeValue-100<=currentUserLatitude)) && ((longitudeValue+100<=currentUserLongitude) ||(longitudeValue-100<=currentUserLongitude)) ){ //alterar os valores, para alterar o radius
LatLng userInteracting = new LatLng(latitudeValue, longitudeValue); //the user that its currently being accessed
mCurrLocationMarker = mMap.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))
.position(userInteracting)
.title(username)); //para mostrar o seu nome ao clicar no marker
mCurrLocationMarker.setTag(userInfo);
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() { //mMap is a GoogleMap object
@Override
public boolean onMarkerClick(Marker marker) {
Intent i = new Intent(MapActivity.this, Pop.class);
String userInfo = (mCurrLocationMarker.getTag()).toString();
i.putExtra("userInfo",userInfo);
startActivity(i);
return false;
}
});
}
}
} else {
Log.d(TAG, "Error getting documents: ", task.getException());
}
}
});
}
所以在这里我试图将userInfo存储到标签中,然后每当我点击标记时我应该检索特定的userInfo,就像我之前所说的那样,它返回两个标记的相同userInfo我有,不应该标记之间的标签不同?我通过FireStore到达userInfo,然后通过每个用户,并为每个用户显示一个标记。
答案 0 :(得分:0)
我认为问题出在你的听众身上
@Override
public boolean onMarkerClick(Marker marker) {
Intent i = new Intent(MapActivity.this, Pop.class);
// Don't use the field mCurrLocationMarker, use the passed in marker object
String userInfo = (marker.getTag()).toString();
i.putExtra("userInfo",userInfo);
startActivity(i);
return false;
}