Google 地图标记比较
Google map markers comparison
我将标记添加到 google 地图。并将引用保留为我的 class 的字段。
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(position)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_aim))
.anchor(0.5f, 0.5f)
.draggable(false);
mCurrentPositionMarker = mView.getGoogleMap().addMarker(markerOptions);
onMarkerClick(Marker marker) returns 一个参考。我只加了一个,所以 (marker == mCurrentPositionMarker) 应该是真的,但它是假的。为什么?
来自文档(强调我的):
The Maps API allows you to listen and respond to marker events. To listen to these events, you must set the corresponding listener on the GoogleMap object to which the markers belong. When the event occurs on one of the markers on the map, the listener's callback will be invoked with the corresponding Marker object passed through as a parameter. To compare this Marker object with your own reference to a Marker object, you must use equals() and not ==.
我将标记添加到 google 地图。并将引用保留为我的 class 的字段。
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(position)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_aim))
.anchor(0.5f, 0.5f)
.draggable(false);
mCurrentPositionMarker = mView.getGoogleMap().addMarker(markerOptions);
onMarkerClick(Marker marker) returns 一个参考。我只加了一个,所以 (marker == mCurrentPositionMarker) 应该是真的,但它是假的。为什么?
来自文档(强调我的):
The Maps API allows you to listen and respond to marker events. To listen to these events, you must set the corresponding listener on the GoogleMap object to which the markers belong. When the event occurs on one of the markers on the map, the listener's callback will be invoked with the corresponding Marker object passed through as a parameter. To compare this Marker object with your own reference to a Marker object, you must use equals() and not ==.