android - 样式化 google 在 Android 中映射我的位置按钮
问题描述
所以我试图使用浮动操作按钮而不是默认的谷歌地图的我的位置按钮。关于我该怎么做的任何想法?我尝试了很多方法,我尝试用true 或 false 调用MyLocationButtonClick()
我内部的事件,但它没有缩放用户位置。欢迎任何帮助!谢谢你的时间!FloatingActionButton
map?.uiSettings?.isMyLocationButtonEnabled
这是我的带有地图的 xml,以及我想为谷歌地图替换我的位置按钮的按钮。
<LinearLayout android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/btn_myLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="8dp"
android:backgroundTint="#fff"
app:borderWidth="0dp"
android:src="@drawable/ic_round_my_location_24"
android:layout_margin="10dp"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"/>
<fragment
android:id="@+id/map"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
</LinearLayout>
这是我的 kotlinonCreate()
和我的浮动按钮点击监听器
val view : View = inflater.inflate(R.layout.fragment_courier_map, container, false)
// starts google places client
Places.initialize(this.requireContext(), getString(R.string.google_maps_key))
placesClient = Places.createClient(requireContext())
// starts fused location
fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(requireContext())
view.btn_myLocation.setOnClickListener {
map!!.setOnMyLocationButtonClickListener {
false
}
}
val mapFragment = childFragmentManager.findFragmentById(R.id.map) as SupportMapFragment?
mapFragment?.getMapAsync(this)
return view
解决方案
您需要按如下方式修改地图的相机,
map.moveCamera(
CameraUpdateFactory.newLatLngZoom(location, DEFAULT_ZOOM.toFloat()))
放大用户位置。阅读本文了解更多详情
推荐阅读
- c# - 在asp.net核心中使用.Net标准项目导致json序列化异常
- apache-kafka - Kafka中的事务超时
- gcc - 如何修改链接描述文件以将代码放入有间隙的闪存中?
- azure - ForEach-Object - 尝试循环变量中的每个地址
- python - 启用多页应用程序后,破折号选项卡停止加载
- linux - 无论 /dev/sda1 中的 EBS 如何,如何使 AWS EC2 允许 ssh 连接?
- python-3.x - 修复 Tkinter GUI 的缩放坐标
- python - 如何栅格化每日地理数据表?
- c++ - C++指针的地址
- vue.js - bootstrap-vue table - 多数据过滤器