【发布时间】:2017-08-19 01:21:23
【问题描述】:
我正在研究谷歌地图 v2。 我在自定义地图片段中实现 OnMapReadyCallback,但一旦片段开始,它就不会触发 onMapReady。
我的代码:
public class CustomMapFragment extends Fragment implements OnMapReadyCallback,GoogleMap.OnMarkerClickListener{
OnCreateView
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
rootView = inflater.inflate(R.layout.fragment_custom_map, container, false);
mMapView = (MapView) rootView.findViewById(R.id.mapView);
mMapView.onCreate(savedInstanceState);
mMapView.onResume(); // needed to get the map to display immediately
try {
MapsInitializer.initialize(this.getActivity());
} catch (Exception e) {
e.printStackTrace();
}
mMapView.getMapAsync(this);
return rootView;
}
重写方法
@Override
public void onMapReady(GoogleMap mMap) {
googleMap = mMap;
googleMap.setMyLocationEnabled(true);
LatLng mMyLocation = new LatLng(mLat, mLng);
CameraPosition cameraPosition = new CameraPosition.Builder().target(mMyLocation).zoom(13).build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
Log.d("Map", "OnMapReady");
googleMap.setOnMarkerClickListener(this);
}
四处寻找,但没有运气。
【问题讨论】:
-
Log.d("Map", "OnMapReady");没有显示任何内容? -
不,完全没有显示。那就是我确认 OnMapReady 根本不会触发。
-
你在哪里测试这个应用程序?
-
在我的设备上测试过。
标签: android google-maps