我无法从 map 获取我的位置,它会引发空指针异常。
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
try {
mMap = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.mapFrag)).getMap();
} catch (Exception e) {
e.printStackTrace();
}
}
// Check if we were successful in obtaining the map.
if (mMap != null) {
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
mMap.setMyLocationEnabled(true);
mMap.getUiSettings().setMyLocationButtonEnabled(true);
mMap.getUiSettings().setZoomControlsEnabled(true);
putMarkerOnMap(mMap.getMyLocation().getLatitude(),mMap.getMyLocation().getLongitude());
}
它在行抛出错误..我调用函数 putMarkerOnMap(lat,lng) 这是那个函数
public void putMarkerOnMap(double la , double lo){
LatLng position = new LatLng(la,lo);
mMap.addMarker(new MarkerOptions().position(new LatLng(la, lo)).title("Your Location"));
CameraPosition campos = new CameraPosition.Builder().target(position).zoom(15)
.bearing(90)
.tilt(40)
.build();
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(campos));
}