我想谷歌地圖標記添加此HashMap:添加標記到一個HashMap,而不將其添加到地圖
private HashMap<Marker, MyMarker> mMarkersHashMap;
沒有將其添加到谷歌地圖。這是我目前擁有的代碼:
MarkerOptions markerOption = new MarkerOptions().position(new LatLng(myMarker.getmLatitude(), myMarker.getmLongitude()));
Marker currentMarker = mMap.addMarker(markerOption);
mMarkersHashMap.put(currentMarker, myMarker);
此代碼添加標記到HashMap中又增添了標記到地圖(使用addMarker),我不想要的。任何建議
下面是函數我的工作:
private void plotMarkers(ArrayList<MyMarker> markers)
{
if(markers.size() > 0)
{
for (final MyMarker myMarker : markers)
{
MarkerOptions markerOption = new MarkerOptions().position(new LatLng(myMarker.getmLatitude(), myMarker.getmLongitude()));
Marker currentMarker = mMap.addMarker(markerOption);
//Passes markers into hashmap so they can be used by the information window methods
mMarkersHashMap.put(currentMarker, myMarker);
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
Intent ListIntent = new Intent(getApplicationContext(), InfoWindowList.class);
MyMarker myMarker = mMarkersHashMap.get(marker);
String title = myMarker.getmLabel();
ListIntent.putExtra("COUNTY", title);
startActivity(ListIntent);
}
});
mMap.setInfoWindowAdapter(new MarkerInfoWindowAdapter());
}
}
mClusterManager.addItems(markers);
}
我想mClusterManager.addItems(markers);
的標記添加到地圖中。
這裏是我的信息窗口功能,需要HashMap中設置的信息窗口在HashMap中的標記:
public class MarkerInfoWindowAdapter implements GoogleMap.InfoWindowAdapter
{
public MarkerInfoWindowAdapter()
{
}
@Override
public View getInfoWindow(Marker marker)
{
return null;
}
@Override
public View getInfoContents(Marker marker)
{
View v = getLayoutInflater().inflate(R.layout.infowindow_layout, null);
MyMarker myMarker = mMarkersHashMap.get(marker);
ImageView markerIcon = (ImageView) v.findViewById(R.id.marker_icon);
TextView markerLabel = (TextView)v.findViewById(R.id.marker_label);
TextView anotherLabel = (TextView)v.findViewById(R.id.another_label);
//anotherLabel.setOnClickListener(newsfeed);
markerIcon.setImageResource(manageMarkerIcon(myMarker.getmIcon()));
anotherLabel.setText("Newsfeed");
markerLabel.setText(myMarker.getmLabel());
return v;
}
}
的MyMarker類:
public class MyMarker implements ClusterItem {
private String mLabel;
private String mIcon;
private Double mLatitude;
private Double mLongitude;
private final LatLng mPosition;
public MyMarker(String label, String icon, Double latitude, Double longitude)
{
this.mLabel = label;
this.mLatitude = latitude;
this.mLongitude = longitude;
this.mIcon = icon;
mPosition = new LatLng(latitude, longitude);
}
//mPosition = LatLng(mLatitude, mLongitude);
@Override
public LatLng getPosition() {
return mPosition;
}
public String getmLabel()
{
return mLabel;
}
public void setmLabel(String mLabel)
{
this.mLabel = mLabel;
}
public String getmIcon()
{
return mIcon;
}
public void setmIcon(String icon)
{
this.mIcon = icon;
}
public Double getmLatitude()
{
return mLatitude;
}
public void setmLatitude(Double mLatitude)
{
this.mLatitude = mLatitude;
}
public Double getmLongitude()
{
return mLongitude;
}
public void setmLongitude(Double mLongitude)
{
this.mLongitude = mLongitude;
}
}
只是不添加標記,以你映射只有到HashMap中,你可以發表你的類的更多的代碼。 –
我知道這是我必須做的,我想知道它是如何完成的。是的,我現在將添加更多的代碼 – Cian