我希望你能帮我解决这个错误。我有一个带有几个标记的地图。在实现Cluster Markers之前,我可以显示带有标题和自定义图标的infoWindows,但现在使用Cluster Markers我不知道如何做到这一点。
我读过几篇文章,但我无法解决这个问题。如果有人知道我做错了什么,请帮助..
这是我的代码。
AsynTask我用标记填充地图
class AllAlojamientos extends AsyncTask<String, String, String>{
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(MapsV2General.this.getActivity());
pDialog.setMessage("Loading... Please wait a moment.");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected String doInBackground(String... args) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
JSONObject json = jParser.makeHttpRequest(url_todos_alojamientos, "GET", params);
try{
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
alojamiento = json.getJSONArray(TAG_ALOJAMIENTO);
} else {
//
}
} catch (JSONException e){
pDialog.dismiss();
e.printStackTrace();
} catch (NullPointerException e){
pDialog.dismiss();
}
return null;
}
@Override
protected void onPostExecute(String a) {
super.onPostExecute(a);
pDialog.dismiss();
try{
for (int i = 0; i < alojamiento.length(); i++) {
JSONObject c = alojamiento.getJSONObject(i);
Marker marker = googleMap.addMarker(new MarkerOptions().position(
new LatLng(Double.parseDouble(c.getString(TAG_LATITUD)), Double.parseDouble(c.getString(TAG_LONGITUD)))).title(c.getString(TAG_NOMBRE))
.snippet(c.getString(TAG_DIRECCION))
.icon(BitmapDescriptorFactory.fromResource(R.drawable.home)));
marker.showInfoWindow();
//Default LatLng Santiago
String latitud = "-33.495542";
String longitud= "-70.662749";
// Move Camera
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(Double.parseDouble(latitud),
Double.parseDouble(longitud))).zoom(15).build();
googleMap.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
googleMap.setOnCameraChangeListener(clusterManager);
googleMap.setOnMarkerClickListener(clusterManager);
double latitudItem = Double.parseDouble(c.getString(TAG_LATITUD));
double longitudItem = Double.parseDouble(c.getString(TAG_LONGITUD));
clusterManager.setRenderer(new MyClusterRenderer(getActivity(), googleMap, clusterManager));
MyItem offsetItem = new MyItem(latitudItem, longitudItem);
clusterManager.addItem(offsetItem);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
这是MyItem类
public class MyItem implements ClusterItem {
private final LatLng mPosition;
private String mTitle;
BitmapDescriptor icon;
String snippet;
public MyItem(double lat, double lng){
mPosition = new LatLng(lat, lng);
}
@Override
public LatLng getPosition() {
return mPosition;
}
public String getTitle(){
return mTitle;
}
public void setTitle(String title){
mTitle = title;
}
}