Android 映射V2 myLocation蓝点回调

Android 映射V2 myLocation蓝点回调,android,google-maps,map,android-maps-v2,mylocationoverlay,Android,Google Maps,Map,Android Maps V2,Mylocationoverlay,我希望能够单击地图上显示的蓝点(我的位置)。是否有任何方法可以从该单击中获得回调 谢谢, Martijn一个可能的解决方法可能是在“我的位置”点的顶部绘制一个标记()(带有类似的图标),以便您可以接收相应的onMarkerClick()回调。这还需要在每次发生位置更新事件时删除标记并将其添加到新位置,您可以通过实现OnMyLocationChangeListener来侦听该事件 编辑:现在不推荐使用OnMyLocationChangeListener接口,应该使用新的和关联的 因此,相关代码可能

我希望能够单击地图上显示的蓝点(我的位置)。是否有任何方法可以从该单击中获得回调

谢谢,
Martijn

一个可能的解决方法可能是在“我的位置”点的顶部绘制一个
标记(
)(带有类似的图标),以便您可以接收相应的
onMarkerClick()
回调。这还需要在每次发生位置更新事件时删除标记并将其添加到新位置,您可以通过实现
OnMyLocationChangeListener
来侦听该事件

编辑:现在不推荐使用
OnMyLocationChangeListener
接口,应该使用新的和关联的

因此,相关代码可能看起来像这样(我实际上没有测试过):


谢谢你的回复。我想这是一项很好的工作,我已经实现了。我只是不明白为什么api不提供这个,谁不想点击myLocation?!而且据我所知,v1api确实提供了它(尽管我从未使用过V1映射)。@Tinus81很高兴它能为您工作。我认为这项功能将在将来添加。顺便说一句,我已经为此制作了一个完全透明的自定义标记。用户不会注意到地图应用程序的差异!
public class DemoMapFragment extends SupportMapFragment implements OnMyLocationChangeListener, OnMarkerClickListener { 

    // Note that 'mMap' may be null if the Google Play services APK is not available. 
    private GoogleMap mMap; 
    private Marker myLocationMarker;
    private static BitmapDescriptor markerIconBitmapDescriptor;
    /* ... */

    @Override 
    public void onResume() { 
        super.onResume(); 
        setUpMapIfNeeded(); // Get a reference to the map      
        mMap.setMyLocationEnabled(true); // Enable the my-location layer 
        mMap.setOnMyLocationChangeListener(this); 
        mMap.setOnMarkerClickListener(this);
    }

    private void setUpMapIfNeeded() { 
        // Do a null check to confirm that we have not already instantiated the map. 
        if (mMap == null) { 
            mMap = getMap(); 
            // Check if we were successful in obtaining the map. 
            if (mMap != null) { 
                // The Map is verified. It is now safe to manipulate the map:

                // Load custom marker icon
                markerIconBitmapDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.my_location_dot_icon); 

                // When the map is first loaded we need to add our marker on top of My Location dot
                myLocationMarker = mMap.addMarker(new MarkerOptions() 
                        .position(new LatLng(mMap.getMyLocation().getLatitude(),mMap.getMyLocation().getLongitude())) 
                        .icon(markerIconBitmapDescriptor)); 

                // Set default zoom 
                mMap.moveCamera(CameraUpdateFactory.zoomTo(15f)); 
            } 
        } 
    }   

    @Override
    public void onMyLocationChange(Location location) {
        // Remove the old marker object
        myLocationMarker.remove(); 

        // Add a new marker object at the new (My Location dot) location
        myLocationMarker = mMap.addMarker(new MarkerOptions() 
                .position(new LatLng(location().getLatitude(),location().getLongitude())) 
                .icon(markerIconBitmapDescriptor)); 
    }

    @Override
    public boolean onMarkerClick(Marker marker) {
        if (marker.equals(myLocationMarker)) {
            /* My Location dot callback ... */
        }
    }
}