I think the problem is in your drawMap
:
public void drawMap(){
Log.d("drawMap","drawMap");
if(friendsMap != null){
MapsInitializer.initialize(getActivity());
friendsMap = ((MapView)friendsGroupMapFragmentView.findViewById(R.id.mapfriends)).getMap();
if(friendsMap == null){
Log.d("NULL","NULL");
}
LatLng chennai = new LatLng(13.0839,80.2700);
friendsMap.moveCamera(CameraUpdateFactory.newLatLng(chennai));
}
}
You are creating map here only when it is already created :) Try to change to
if(friendsMap == null)
{
....
}
EDIT
I completely missed that you use MapView
instead of MapFragment.
With MapView
you need to pass all the fragment lifecycle events (onCreate
, onDestroy
, onResume
, etc) to your MapView
. See this section of docs
The only thing I would mention is that since you inflate MapView
inside fragment, you need to call MapView
's onCreate
inside onCreateView()
:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
Log.d("ON CREATEVIEW()","ON CREATEVIEW()");
friendsGroupMapFragmentView = inflater.inflate(R.layout.fragment_friends_group_map, container, false);
this.mapView = (MapView)friendsGroupMapFragmentView.findViewById(R.id.mapfriends);
this.mapView.onCreate(savedInstanceState);
drawMap();
return friendsGroupMapFragmentView;
}
@Override
public View onResume() {
this.mapView.onResume();
.....
}
And so on