【发布时间】:2016-05-31 12:08:42
【问题描述】:
我在 Fragment 中实现 Google 地图时遇到问题。
这是我的片段类的一部分:
public class FragmentStoreFinderMap extends Fragment implements OnMapReadyCallback {
// Google Map
private GoogleMap googleMap;
private int i;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
googleMap = ((SupportMapFragment)getActivity().getSupportFragmentManager().findFragmentById(
R.id.map)).getMapAsync(this);
我在 getMapAsync(this) 中遇到错误。我告诉不兼容的类型。
上面写着:
必需:com.google.android.gms.map.GoogleMap
发现:无效
顺便说一句,这是我的 xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment class="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
【问题讨论】:
标签: android google-maps android-fragments android-studio supportmapfragment