问题描述
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 (将#修改为@)