gpt4 book ai didi

android - 在华为 mapkit 中获取我的位置按钮的引用

转载 作者:行者123 更新时间:2023-12-04 08:26:35 24 4
gpt4 key购买 nike

我正在使用华为 MapKit,我想添加我的自定义 MyLocationButton但我不想使用位置管理器来获取我的位置并移动到它,我只想huaweiMapMyLocationButton.performClick() ,例如,使用谷歌地图我可以做到这一点

val locationButtonParent = view?.findViewById<View>(Integer.parseInt("1"))?.parent as? View?
val locationButton = locationButtonParent?.findViewById<View>(Integer.parseInt("2"))
locationButton.performClick()
我想要华为 map 这样的东西,我能够通过 map View 的 subview ,我找到了 ui 设置 View (缩放、指南针、位置)并按照我能够得到的位置:
val mapFragment = childFragmentManager.findFragmentById(R.id.map) as SupportMapFragment
val fragmentView = mapFragment.view
val myLocationButton =
((((fragmentView as ViewGroup).getChildAt(0) as ViewGroup).getChildAt(1) as ViewGroup).getChildAt(
1
) as ViewGroup).getChildAt(0)
但这没有用

最佳答案

您在 HUAWEI Map Kit 中使用的 MapView 图层不正确。无需根据 Google 的图层解析 map 。
请尝试使用以下代码测试implementation' com.huawei.hms:maps:5.0.5.301 '并添加自定义 MyLocationButton .

//...
MapView mapView = mMapView;
dumpMapViewClickLoctionBtn(mapView, "location");
}
}

private void dumpMapViewClickLoctionBtn(ViewGroup viewGroup, String id) {
for (int j = 0; j < viewGroup.getChildCount(); j++) {
View view = viewGroup.getChildAt(j);
if (view.toString().contains(id)) {
view.performClick();
}
if (view instanceof ViewGroup) {
ViewGroup v = (ViewGroup) view;
dumpMapViewClickLoctionBtn(v,id);
}
}
}

关于android - 在华为 mapkit 中获取我的位置按钮的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65234040/

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