如何禁用在Android中点击地图标记? [英] How do I disable click on a map marker in android?
本文介绍了如何禁用在Android中点击地图标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了我的自定义位置侦听器,它每10分钟检查用户的位置,并更新地图上标记用户位置的标记。问题是标记是可点击的,即它显示一个按钮来获取标记的方向。我想禁用它,我该怎么做?
以下是创建/更新标记的函数
public void updateUserMarker(){
Double temp_latitude =((MainActivity)mContext).mLatitude;
Double temp_longitude =((MainActivity)mContext).mLongitude;
if(mMap!= null){
if(user_marker == null){
MarkerOptions markerOptions = new MarkerOptions()。position(new LatLng(temp_latitude,temp_longitude)) ;
markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.my_marker_icon));
user_marker = mMap.addMarker(markerOptions);
} else {
user_marker.setPosition(new LatLng(temp_latitude,temp_longitude));
$ b $ / code $ / pre>
解决方案
mMap.setOnMarkerClickListener(新的GoogleMap.OnMarkerClickListener(){
@Override
public boolean onMarkerClick(Marker marker){
return true;
}
});
返回true还会阻止打开信息窗口。
将它与 ClusterManager
一起使用:
mMap .setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener(){
@Override
public boolean onMarkerClick(Marker marker){
if(marker == user_marker){
return true;
}
返回clusterManager.onMarkerClick(marker);
}
});
I've written my custom location listener which checks the user's location in every 10 minutes and updates a marker on the map which denotes the user's location. The problem is that the marker is clickable i.e. it shows a button to get directions to the marker. I want to disable that, how can I do that?
Here's the function which creates/updates the marker
public void updateUserMarker() {
Double temp_latitude = ((MainActivity)mContext).mLatitude;
Double temp_longitude = ((MainActivity)mContext).mLongitude;
if(mMap!=null) {
if (user_marker == null) {
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng(temp_latitude, temp_longitude));
markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.my_marker_icon));
user_marker = mMap.addMarker(markerOptions);
} else {
user_marker.setPosition(new LatLng(temp_latitude, temp_longitude));
}
}
}
解决方案 Try this code.
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
return true;
}
});
Returning true will also prevent info window from being opened.
For using this with a ClusterManager
:
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
if (marker == user_marker) {
return true;
}
return clusterManager.onMarkerClick(marker);
}
});
这篇关于如何禁用在Android中点击地图标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文