旧代码以这种方式完美运行:
LatLng location = new LatLng (myClass.myLocation.Latitude,myClass.myLocation.Longitude); CameraPosition.Builder builder = CameraPosition.InvokeBuilder (); builder.Target (location); builder.Zoom (18); CameraPosition cameraPosition = builder.Build (); MapsInitializer.Initialize (this); CameraUpdate cameraUpdate = CameraUpdateFactory.NewCameraPosition (cameraPosition); MapFragment googleMap = FragmentManager.FindFragmentById<MapFragment> (Resource.Id.map); theMap = googleMap.Map; if (theMap != null) { theMap.MapType = GoogleMap.MapTypeNormal; theMap.MoveCamera (cameraUpdate); }
但是现在.Map已经过时并且已弃用,我必须以某种方式使用.GetMapAsync:
theMap = googleMap.GetMapAsync (IOnMapReadyCallback);
但我不明白怎么做.
有人可以帮助我吗?
解决方法
您的地图片段类必须实现OnMapReadyCallback并覆盖onMapReady():
@Override public void onMapReady(final GoogleMap map) { this.map = map; map.setMyLocationEnabled(true); }
在onCreateView中使用getMapAsync()来设置片段的回调:
MapFragment mapFragment = (MapFragment) getFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this);
您需要实现谷歌地图V2所需的一切:
https://developers.google.com/maps/documentation/android/map