class MapsActivity : AppCompatActivity(), OnMapReadyCallback {
// Define an enum for marker types
enum class MarkerType(val resourceId: Int, val scale: Float) {
DEFAULT(-1, 1.0f), // Use -1 to indicate no custom marker
CUSTOM_1(R.drawable.icon_circle, 0.4f),
CUSTOM_2(R.drawable.circle_arrow, 0.6f)
}
private lateinit var mMap: GoogleMap
private lateinit var binding: ActivityMapsBinding
private val LOCATION_PERMISSION_REQUEST_CODE = 1
private var points: ArrayList<LatLng>? = null
private var line: Polyline? = null
private lateinit var rotatingMarker: RotatingMarker
private lateinit var locationClient: FusedLocationProviderClient
private var userLocation: LatLng = LatLng(0.0, 0.0)
// Location callback defined here
private val locationCallback = object : LocationCallback() {
fun onLocationResult(locationResult: LocationResult?) {
locationResult?.lastLocation?.let { location ->
// Handle the new location here
val newLocation = LatLng(location.latitude, location.longitude)
updateMarkerPosition(newLocation)
}
}
}
字符串
错误/S:
e:file:/D:/Android_Studio_Projects/Live_Route/app/src/main/java/com/example/liveroute/MapsActivity.kt:55:9意外覆盖:以下声明具有相同的JVM签名(onLocationResult(Lcom/google/android/gms/location/LocationResult;)V):fun onLocationResult(p0:LocationResult):Unit defined in com. example. liveroute. MapsActivity. <no name provided>
fun onLocationResult(locationResult:LocationResult?):Unit defined in com. example. liveroute. MapsActivity. <no name provided>
当我在乐趣之前添加覆盖时,比如:
private val locationCallback = object : LocationCallback() {
override fun onLocationResult(locationResult: LocationResult?) {
locationResult?.lastLocation?.let { location ->
// Handle the new location here
val newLocation = LatLng(location.latitude, location.longitude)
updateMarkerPosition(newLocation)
}
}
}
型
我就会在超驰上出错
'onLocationResult'不覆盖任何内容
1条答案
按热度按时间c0vxltue1#
错误“onLocationResult overrides nothing”是因为您忘记在覆盖中调用
super.onLocationResult()
而导致的。因此,根据您的情况,添加
super
调用。字符串
记住在覆盖中包含
super
调用。编辑
如果你不想叫管理员:
发件人:
型
收件人:
型
删除函数参数中
LocationResult
的可空值(?
符号)。同样,这样做,你不必调用
super.onLocationResult()
。你可以从官方文档中找到更多关于super和classes的信息。