You want to show more data in marker info window so you need to put some data in marker when it create .you should make some new things like that:
1. Firstly create a hash map to put the value.
HashMap<String, String> map = new HashMap<>();
map.put("userId", userId);
map.put("userName", name);
if(profileImage.equalsIgnoreCase(""))
map.put("imageUrl", null);
else
map.put("imageUrl", profileImage);
map.put("primaryInstrumentName", primary_Instrument_name);
googleMap.addMarker(new MarkerOptions()
.position(new LatLng(Double.valueOf(latitude), Double.valueOf(lonnitude))).snippet(String.valueOf(map))
.icon(R.drawable.marker);
when u set listner on google map info window its return the marker object get marker.getsnippet which return the hashmap type string convert it in single key value according to this code:
private Map<String, String> getMarkerDetails(Marker marker) {
String name2 = marker.getSnippet();
System.out.println("name "+name2);
name2 = name2.substring(1, name2.length() - 1);
String[] keyValuePairs = name2.split(",");
Map<String, String> map = new HashMap<>();
for (String pair : keyValuePairs) {
String[] entry = pair.split("=");
System.out.println("name map is "+entry[0]+" "+entry[1]);
map.put(entry[0].trim(), entry[1].trim());
}
return map;
}
this would help to get back key value from string hashmap using this like:
getMarkerDetails(marker).get("userName").toString();
this will return to marker "username" data , use wherever need.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…