如何解决在 Kotlin 中将折线保存到 Firebase?
override fun onViewCreated(view: View,savedInstanceState: Bundle?) {
super.onViewCreated(view,savedInstanceState)
val mapFragment = childFragmentManager.findFragmentById(R.id.map) as SupportMapFragment?
mapFragment?.getMapAsync(this)
}
@SuppressLint("MissingPermission","PotentialBehaviorOverride")
override fun onMapReady(googleMap: GoogleMap?) {
map = googleMap!!
map.isMyLocationEnabled = true
map.setonMyLocationButtonClickListener(this)
map.setonMarkerClickListener(this)
map.uiSettings.apply {
isZoomControlsEnabled = false
isZoomGesturesEnabled = false
isRotateGesturesEnabled = false
isTiltGesturesEnabled = false
isCompassEnabled = false
isScrollGesturesEnabled = false
}
observeTrackerService()
}
private fun observeTrackerService() {
TrackerService.locationList.observe(viewLifecycleOwner,{
if (it != null) {
locationList = it
if (locationList.size > 1) {
binding.stopButton.enable()
}
drawpolyline()
followpolyline()
}
})
TrackerService.started.observe(viewLifecycleOwner,{
started.value = it
})
TrackerService.startTime.observe(viewLifecycleOwner,{
startTime = it
})
TrackerService.stopTime.observe(viewLifecycleOwner,{
stopTime = it
if (stopTime != 0L) {
showBiggerPicture()
displayResults()
}
})
}
private fun drawpolyline() {
val polyline = map.addpolyline(
polylineoptions().apply {
width(10f)
color(Color.BLUE)
jointType(JointType.ROUND)
startCap(ButtCap())
endCap(ButtCap())
addAll(locationList)
}
)
polylineList.add(polyline)
}
private fun followpolyline() {
if (locationList.isNotEmpty()) {
map.animateCamera(
(CameraUpdateFactory.newCameraPosition(
setCameraPosition(
locationList.last()
)
)),1000,null)
}
}
}
private fun showBiggerPicture() {
val bounds = LatLngBounds.Builder()
for (location in locationList) {
bounds.include(location)
}
map.animateCamera(
CameraUpdateFactory.newLatLngBounds(
bounds.build(),100
),2000,null
)
addMarker(locationList.first())
addMarker(locationList.last())
}
private fun addMarker(position: LatLng){
val marker = map.addMarker(MarkerOptions().position(position))
markerList.add(marker)
}
private fun displayResults() {
val result = Result(
calculateThedistance(locationList),calculateelapsedtime(startTime,stopTime)
)
lifecycleScope.launch {
delay(2500)
val directions = MapsFragmentDirections.actionMapsFragmentToResultFragment(result)
findNavController().navigate(directions)
binding.startButton.apply {
hide()
enable()
}
binding.stopButton.hide()
binding.resetButton.show()
} `
我想将折线发送到 Firestore。如何将代码中的折线发送到 Firestore?任何人都可以帮忙吗?我的代码有一个带按钮的地图片段。这是一个距离跟踪应用程序。该应用程序使用折线绘制距离。如何将折线转换为数组。在这里,我正在做一个位置跟踪应用程序。我想将折线转换为数组,以便我可以将其保存在云中。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。