【发布时间】:2016-01-16 00:19:42
【问题描述】:
这里有一个很好的在 android 上设置谷歌地图的教程: https://gist.github.com/joshdholtz/4522551
我可以在我的应用程序中运行它。
但最近谷歌将getMapAsync()替换为getMap()
这是新的谷歌教程: https://developers.google.com/maps/documentation/android-api/start
我尝试将其转换为片段:
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" />
但是在调试级别我得到了这个错误:
Error:(24, 75) error: inconvertible types
required: MapFragment
found: Fragment
在这一行:
gMapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
我怎么了?
【问题讨论】:
标签: android google-maps android-fragments