我想减少。触摸标记的焦点区域。虽然点击面积太大,我想缩短谷歌Map上标记的点击面积。我是新的Map,我想知道我们如何才能减少填充标记在重点在android。
7y4bm7vi1#
<View android:id="@+id/transparentOverlay" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/transparent" />
then inside onMapReady, I implemented this code - binding.transparentOverlay.setOnClickListener { view -> val mapClickPoint = Point(view.x.toInt(), view.y.toInt()) val mapLatLng = map.projection.fromScreenLocation(mapClickPoint) if (this::carMarker.isInitialized) { if (isPointInMarkerClickableArea(carMarker, mapLatLng)) { // The click was within the custom clickable area of the marker // Handle the marker click here markerClickAction(carMarker) } } } private fun isPointInMarkerClickableArea(marker: Marker, clickLatLng: LatLng): Boolean { // Calculate the distance between the marker's position and the clickLatLng // If the distance is within a certain threshold, consider it a click on the marker val distanceThreshold = 50 // in pixels, adjust as needed val markerPosition = marker.position val markerScreenPosition = map.projection.toScreenLocation(markerPosition) val clickScreenPosition = map.projection.toScreenLocation(clickLatLng) val distance = Math.sqrt(Math.pow((markerScreenPosition.x - clickScreenPosition.x).toDouble(), 2.0) + Math.pow((markerScreenPosition.y - clickScreenPosition.y).toDouble(), 2.0)) return distance <= distanceThreshold } private fun markerClickAction(carMarker: Marker) { // Implement your action when the marker is clicked // For example, show an info window, navigate to a detailed view, etc. Toast.makeText(this, "Click on marker: ${carMarker.title}", Toast.LENGTH_SHORT).show() }
then inside onMapReady, I implemented this code -
binding.transparentOverlay.setOnClickListener { view ->
val mapClickPoint = Point(view.x.toInt(), view.y.toInt())
val mapLatLng = map.projection.fromScreenLocation(mapClickPoint)
if (this::carMarker.isInitialized) {
if (isPointInMarkerClickableArea(carMarker, mapLatLng)) {
// The click was within the custom clickable area of the marker
// Handle the marker click here
markerClickAction(carMarker)
}
} private fun isPointInMarkerClickableArea(marker: Marker, clickLatLng: LatLng): Boolean {
// Calculate the distance between the marker's position and the clickLatLng
// If the distance is within a certain threshold, consider it a click on the marker
val distanceThreshold = 50 // in pixels, adjust as needed
val markerPosition = marker.position
val markerScreenPosition = map.projection.toScreenLocation(markerPosition)
val clickScreenPosition = map.projection.toScreenLocation(clickLatLng)
val distance = Math.sqrt(Math.pow((markerScreenPosition.x - clickScreenPosition.x).toDouble(), 2.0) +
Math.pow((markerScreenPosition.y - clickScreenPosition.y).toDouble(),
2.0))
return distance <= distanceThreshold } private fun markerClickAction(carMarker: Marker) {
// Implement your action when the marker is clicked
// For example, show an info window, navigate to a detailed view, etc.
Toast.makeText(this, "Click on marker: ${carMarker.title}", Toast.LENGTH_SHORT).show() }
字符串
1条答案
按热度按时间7y4bm7vi1#
<View android:id="@+id/transparentOverlay" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/transparent" />
中添加一个覆盖字符串