首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Google不按片段加载

Google不按片段加载
EN

Stack Overflow用户
提问于 2016-04-09 21:51:37
回答 1查看 789关注 0票数 1

我有一个带有两个窗口的滑动选项卡片段,第一个窗口包含一个google地图视图。片段正常工作,Google片段也显示出来,但是地图没有加载。只显示带有网格线和google徽标的空白地图。我的密码怎么了?

代码语言:javascript
运行
复制
public class CardFragment extends Fragment implements OnMapReadyCallback{

private static final String ARG_POSITION = "position";
private int position;

GoogleMap mMap;
Geocoder coder;

public static CardFragment newInstance(int position) {
    CardFragment f = new CardFragment();
    Bundle b = new Bundle();
    b.putInt(ARG_POSITION, position);
    f.setArguments(b);
    return f;
}

public static MapsFragment newInstance(String s) {
    Bundle args = new Bundle();
    args.putString("value", s);
    MapsFragment result = new MapsFragment();
    result.setArguments(args);
    return result;
}


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    position = getArguments().getInt(ARG_POSITION);      
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if(position == 0){
        View rootView = inflater.inflate(R.layout.maps_frag,container,false);
        ButterKnife.inject(this, rootView);
        ViewCompat.setElevation(rootView, 50);

        if(GooglePlayServicesUtil.isGooglePlayServicesAvailable(this.getContext()) == ConnectionResult.SUCCESS) {

            MapView mapView = (MapView) rootView.findViewById(R.id.mymap);
            mapView.onCreate(savedInstanceState);
            mapView.getMapAsync(this);
        }

        return rootView;
    } else {
        View rootView = inflater.inflate(R.layout.list_frag,container,false);
        ViewCompat.setElevation(rootView, 50);
        return rootView;
}


@Override
public void onMapReady(final GoogleMap googleMap) {

    mMap = googleMap;
    coder = new Geocoder(this.getContext());
    p1 = null;
}

布局maps_frag

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.CardView
android:id="@+id/cardview"
android:layout_width="match_parent"
android:layout_height="match_parent"
card_view:cardBackgroundColor="@android:color/white">

<com.google.android.gms.maps.MapView     xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/swagishmap"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.locustapps.ingredientsapp.MapsActivity"/>

</android.support.v7.widget.CardView>

</FrameLayout>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-09 22:30:06

我不明白你为什么要用MapView来命名com.google.android.gms.maps.SupportMapFragment。这没有任何意义。

如果要将Map放入片段中,则如果对片段使用兼容性库,则应该使用MapFragmentSupportMapFragment。这些片段将管理在片段空间中地图的显示。

ApiDemos示例项目有如何使用它的示例。声明一个这是一个布局片段的SupportMapView。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36523159

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档