我希望能够单击地图上显示的蓝点(我的位置).无论如何,该点击是否会产生回调?
谢谢,
马亭
解决方法:
一种可能的解决方法是在“我的位置”点上方绘制一个标记(带有类似图标),以便您可以接收到相应的onMarkerClick()回调.这还需要在每次发生位置更新事件时都删除标记并将其添加到新位置,您可以通过实现OnMyLocationchangelistener来侦听该事件.
编辑:现在不建议使用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 ... */ } }}
总结 以上是内存溢出为你收集整理的android-Maps V2 myLocation蓝点回调全部内容,希望文章能够帮你解决android-Maps V2 myLocation蓝点回调所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)