android中的片段 –getMapAsync()

android中的片段 –getMapAsync(),第1张

概述我在Fragment中实现GoogleMap时遇到了麻烦.这是我的片段类的一部分:publicclassFragmentStoreFinderMapextendsFragmentimplementsOnMapReadyCallback{//GoogleMapprivateGoogleMapgoogleMap;privateinti;@OverridepublicvoidonCreate(BundlesavedInstanc

我在Fragment中实现Google Map时遇到了麻烦.

这是我的片段类的一部分:

public class FragmentStoreFinderMap extends Fragment implements OnMapReadyCallback {// Google Mapprivate GoogleMap GoogleMap;private int i;@OverrIDepublic 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     androID:ID="@+ID/map"    androID:name="com.Google.androID.gms.maps.SupportMapFragment"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"/></linearLayout>

解决方法:

在您的XML布局中,您应该这样做

<FrameLayout 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"><com.Google.androID.gms.maps.MapVIEw    androID:ID="@+ID/map"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"/></FrameLayout>

在你的片段里面实现这个

private MapVIEw mapVIEw;private GoogleMap GoogleMap;

如果没有onCreateVIEw,则覆盖onCreateVIEw,就像下面的代码一样

@OverrIDepublic VIEw onCreateVIEw(LayoutInflater inflater, VIEwGroup container,                         Bundle savedInstanceState) {    // Inflate the layout for this fragment    return inflater.inflate(R.layout.your_layout, container, false);}

在其中覆盖onVIEwCreated()
onVIEwCreated()把这个

mapVIEw = (MapVIEw) vIEw.findVIEwByID(R.ID.map);mapVIEw.onCreate(savedInstanceState);mapVIEw.onResume();mapVIEw.getMapAsync(this);//when you already implement OnMapReadyCallback in your fragment

当你已经在你的片段中实现OnMapReadyCallback时,将这个/代码放在这样的代码中

@OverrIDepublic voID onMapReady(GoogleMap map) {    GoogleMap = map;}

希望这能帮助你.

总结

以上是内存溢出为你收集整理的android中的片段 – getMapAsync()全部内容,希望文章能够帮你解决android中的片段 – getMapAsync()所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1100597.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存