我一直遵循这个guide,直到我意识到他正在将标记直接添加到地图上并且没有让集群管理器来处理它。
我创建了一个实现CustomInfo
的{{1}}类。在InfoWindowAdapter
中,我使用getInfoContents(Marker marker)
从标记中获取数据。问题是我从来没有在标记上设置标签(我在哪里?)。
这是当我读取位置对象时的代码:
getTag()
要将标记添加到地图,我对群集管理器使用以下方法:
private void generateShelterObjects()
{
Log.i(TAG, "METHOD generateShelterObjects() STARTED");
InputStream is = getResources().openRawResource(R.raw.shelters_csv_file);
BufferedReader reader = new BufferedReader(
new InputStreamReader(is, Charset.forName("UTF-8")));
String line = "";
try {
while ((line = reader.readLine()) != null) {
// Split the line into different tokens (using the comma as a separator).
String[] tokens = line.split(",");
String address = tokens[0];
double latitude = Double.parseDouble(tokens[1]);
double longitude = Double.parseDouble(tokens[2]);
LatLng latLng = new LatLng(latitude, longitude);
String numberOfOccupants = tokens[3];
MarkerOptions markerOptions = new MarkerOptions().position(latLng).title(address).snippet("Antal platser: " + numberOfOccupants);
ShelterObject obj = new ShelterObject(latLng, address, numberOfOccupants);
listMarkers.add(markerOptions);
}
} catch (IOException e1) {
Log.e(TAG, "Error" + line, e1);
e1.printStackTrace();
}
}
谢谢!
答案 0 :(得分:0)
检查此
private void setUpcustomInfoWindow(){
myMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker arg0) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
View myContentView =getActivity().getLayoutInflater().inflate(
R.layout.custom_info_window, null);
TextView tvAddress = ((TextView) myContentView
.findViewById(R.id.tv_address_info_window));
TextView tvAveragePrice = ((TextView) myContentView
.findViewById(R.id.tv_averageprice_info_window));
TextView tvAverageSqft = ((TextView) myContentView
.findViewById(R.id.tv_averagesqft_info_window));
MicroLocality microLocality = (MicroLocality) marker.getTag();
tvAddress.setText(microLocality.getMicroLocality());
tvAveragePrice.setText(getActivity().getString(R.string.Rs)+" "+microLocality.getPricerange());
tvAverageSqft.setText(getActivity().getString(R.string.Rs)+" "+microLocality.getPricePerSqft());
return myContentView;
}
});
}