I can load the Google map into an Android fragment that is inside the action. This is working fine.
But now I want to use the ViewPager to navigate between views ( android.support.v4.app.Fragment class). Unable to load 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)); } }
Statement
getFragmentManager().findFragmentById(R.id.holeViewMap);
causes a compiler error (incompatible types).
Instead, I tried using SupportMapFragment, which fixes the compiler errors, but then when I launch the application, it immediately terminates with the message "I / O error: connection refused." Google docs seem to indicate that in order to use the support library you need a special βWorkβ account. It's right? If so, I think Iβm out of luck.
The only way I can do this is to use actions instead of fragments to post my views, i.e. get rid of ViewPager .
Any suggestions?
android android-fragments google-maps fragmentpageradapter
Nlricker
source share