there is a good tutorial to setup google map on android here: https://gist.github.com/joshdholtz/4522551
I can run it in my application.
But recently google replace getMapAsync()
with getMap()
here is new google tutorial: https://developers.google.com/maps/documentation/android-api/start
I try convert it to fragment:
public class MFragment extends Fragment implements OnMapReadyCallback {
MapView gMapView;
GoogleMap gMap = null;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.m_layout, container, false);
gMapView = (MapView) view.findViewById(R.id.map);
gMapView.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));
}
}
m_layout.xml:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
tools:context="MFragment"
android:name="com.google.android.gms.maps.SupportMapFragment" />
But in debug level I got this error:
Error:(24, 75) error: inconvertible types
required: MapFragment
found: Fragment
on this line:
gMapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
what's my wrong?