gpt4 book ai didi

java - 无法为 Android Google map 创建 ClusterManager

转载 作者:行者123 更新时间:2023-12-02 03:52:46 27 4
gpt4 key购买 nike

我正在尝试在我的 Android 项目中使用 Google map 集群。

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

但是,在我的项目上

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

它抛出:

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

我什至不明白为什么会有类型转换?

基本上从以下位置获取了 Activity (以及所有需要的相关类(class)) https://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 上

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

请问有人知道吗?

最佳答案

如果这可以帮助任何人 -

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

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

关于java - 无法为 Android Google map 创建 ClusterManager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35742544/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com