Maps创建ClusterManager

Maps创建ClusterManager

本文介绍了无法为Android Google Maps创建ClusterManager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Android项目中使用Google Maps集群.

I'm trying to use Google Maps clustering in my Android project.

目前,我实际上是从演示中复制了代码 https://github.com/googlemaps/android-maps-utils (对我来说很好)

Currently for a start I actually copied the code from the demohttps://github.com/googlemaps/android-maps-utils (which runs fine for me)

但是在我的项目上

mClusterManager = new ClusterManager<MyItem>(this, getMap());

它抛出:

java.lang.ClassCastException: android.widget.ImageView cannot be cast to com.google.maps.android.ui.RotationLayout

我什至不知道为什么会有什么演员?

I can't even figure out what why is any there casting?

基本上从以下位置获取了活动(以及所有需要的相关类) https://github.com/googlemaps/android-maps-utils/blob/master/demo/src/com/google/maps/android/utils/demo/BigClusteringDemoActivity.java

Basically took the activity (and all needed related classes) fromhttps://github.com/googlemaps/android-maps-utils/blob/master/demo/src/com/google/maps/android/utils/demo/BigClusteringDemoActivity.java

public class ClusteringDemoActivity extends BaseDemoActivity {
private ClusterManager<MyItem> mClusterManager;

@Override
protected void startDemo() {
    getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(51.503186, -0.126446), 10));

    mClusterManager = new ClusterManager<MyItem>(this, getMap());
    getMap().setOnCameraChangeListener(mClusterManager);

    try {
        readItems();
    } catch (JSONException e) {
        Toast.makeText(this, "Problem reading list of markers.", Toast.LENGTH_LONG).show();
    }
}

private void readItems() throws JSONException {
    InputStream inputStream = getResources().openRawResource(R.raw.radar_search);
    List<MyItem> items = new MyItemReader().read(inputStream);
    mClusterManager.addItems(items);
}

public static void launch(Context context) {
    context.startActivity(new Intent(context, ClusteringDemoActivity.class));
}

}

public abstract class BaseDemoActivity extends FragmentActivity {
private GoogleMap mMap;

protected int getLayoutId() {
    return R.layout.map;
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(getLayoutId());
    setUpMapIfNeeded();
}

@Override
protected void onResume() {
    super.onResume();
    setUpMapIfNeeded();
}

private void setUpMapIfNeeded() {
    if (mMap != null) {
        return;
    }
    mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
    if (mMap != null) {
        startDemo();
    }
}

/**
 * Run the demo-specific code.
 */
protected abstract void startDemo();

protected GoogleMap getMap() {
    setUpMapIfNeeded();
    return mMap;
}

}

public class MyItem implements ClusterItem {
private final LatLng mPosition;

public MyItem(double lat, double lng) {
    mPosition = new LatLng(lat, lng);
}

@Override
public LatLng getPosition() {
    return mPosition;
}

}

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

并在我的build.gradle上

and have on my build.gradle

compile 'com.google.android.gms:play-services-maps:8.4.0'
compile 'com.google.maps.android:android-maps-utils:0.3+'

请问有人有主意吗?

推荐答案

万一这可以帮助任何人-

Incase this can help anyone -

我在自己的项目中有一个名为text_bubble.xml的布局这与同名库的布局发生冲突,并导致了异常.

I had in my own project a layout named text_bubble.xmlThis clashed with a layout of the library, by the same name, and it caused the exception.

只需重命名我的布局即可解决此问题.

Simply renaming my layout resolved this.

这篇关于无法为Android Google Maps创建ClusterManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 20:45