无法解析方法"getMapAsync"; [英] Cannot resolve method "getMapAsync"

查看:68
本文介绍了无法解析方法"getMapAsync";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于任何语法错误,请原谅. 我遵循了一个教程来片段查看Google地图,但是出了点问题.

Excuse me for any grammatical errors. I followed a tutorial to view the google map in a fragment, but something has gone wrong.

这是我的文件.java,它与片段挂钩:

this is my file .java that is hooked with the fragment:

public class MapFragment extends Fragment implements OnMapReadyCallback{
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    return inflater.inflate(R.layout.fragment_map, container, false);

}

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    MapFragment fragment = (MapFragment)getChildFragmentManager().findFragmentById(R.id.map);
    fragment.getMapAsync(this); //Here i get the error
}

@Override
public void onMapReady(GoogleMap googleMap) {

}

}

这是布局片段:

<fragment
    android:id="@+id/map"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.MapFragment"></fragment>

我做错了什么?

谢谢!

推荐答案

您必须使用SupportMapFragment而不是MapFragment
用XML

You have to use SupportMapFragment rather than MapFragment
in XML

<fragment
    android:id="@+id/map"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment"></fragment>

在片段中

SupportMapFragment fragment = (SupportMapFragment)getChildFragmentManager().findFragmentById(R.id.map);
fragment.getMapAsync(this);

这篇关于无法解析方法"getMapAsync";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆