我希望能够单击地图上显示的蓝点(我的位置)。无论如何可以从该点击中获得回调吗?
谢谢,
马丁
一种可能的解决方法可能是绘制一个Marker
(带有类似的图标)位于“我的位置”点的顶部,以便您可以收到相应的信息onMarkerClick()
打回来。这还需要删除标记并将其添加到每次发生位置更新事件时的新位置,您可以通过实现来监听该事件OnMyLocationChangeListener
.
EDIT: the OnMyLocationChangeListener
接口现已弃用,应该使用新的接口LocationClient以及相关的LocationListener.
所以相关的代码可能看起来像这样(我没有实际测试过):
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 ... */
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)