I can load a google map into an Android fragment that's within an activity. That has been working fine.
But now I want to use ViewPager to navigate between views (class android.support.v4.app.Fragment
). It doesn't seem possible to load a com.google.android.gms.maps.MapFragment
into such a fragment.
For example, in:
SoleMap.java
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
public class SoleMap extends Fragment implements OnMapReadyCallback {
MapFragment gMapFragment;
GoogleMap gMap = null;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.sole_map, container, false);
gMapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.soleViewMap);
gMapFragment.getMapAsync(this);
return view;
}
@Override
public void onMapReady(GoogleMap map) {
gMap = map;
gMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
gMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new
LatLng(49.39,-124.83), 20));
}
}
The statement
getFragmentManager().findFragmentById(R.id.holeViewMap);
causes a compiler error (incompatible types).
I have tried to use SupportMapFragment instead, which eliminates the compiler errors, but then when I run the app, it quits immediately with the message "I/O Error: Connection refused." The Google docs seem to indicate that you need a special "For Work" account to use the Support library. Is that correct? If so, I guess I'm out of luck.
The only other way I can see to do it is to use activities instead of fragments to host my views, i.e., get rid of the ViewPager.
Any suggestions?