1
我有一張地圖,我有一個數據庫與json查詢。我試圖創建一個有標記(標題等)的地圖。因爲有很多我想到了聚類,所以我實現了它們。但問題是,它不工作,因爲我想要它。當應用程序啓動時,它會顯示地圖,放大您的位置,但不會顯示任何標記或羣集。但是目前你縮小了,集羣顯示了標記等任何想法什麼是錯的?當我在googlemapsv2上啓動應用程序時,羣集不顯示
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = getApplicationContext();
if (getSharedPreferencesRadius() == null) {
SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, Context.MODE_PRIVATE).edit();
editor.putInt("radius", 2000);
editor.commit();
}
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
setUpMapIfNeeded();
}
@Override
public void onMapReady(GoogleMap googleMap) {
this.mMap = googleMap;
setUpMap();
}
@Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
private void setUpMapIfNeeded() {
if (mMap == null) {
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
Log.d("MAP", " "+mMap);
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap() {
mMap.setMyLocationEnabled(true);
setMyLocationLatLng();
kompasEnabled();
radiusEnable(latLng);
ZoomIN(latLng);
mClusterManager = new ClusterManager<Marker>(this, mMap);
mClusterManager.clearItems();
mMap.setOnCameraChangeListener(mClusterManager);
mMap.setOnMarkerClickListener(mClusterManager);
mClusterManager.cluster();
jsonRequest(latitude, longitude);
}
protected GoogleMap getMap() {
setUpMapIfNeeded();
return mMap;
}
,這是activity_main
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/container_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar"></include>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/clayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
tools:context=".MainActivity"
android:name="com.google.android.gms.maps.SupportMapFragment" />
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
如果您需要任何更多的信息,請詢問。
UPDATE 1: 我發現沒有mMap.setOnCameraChangeListener(mClusterManager); 它不起作用(甚至不會顯示它們)。有任何想法嗎?