【问题标题】:problems with google maps api in android studioandroid studio中谷歌地图api的问题
【发布时间】:2016-03-22 23:48:55
【问题描述】:

我已经编写了代码以在我的一个片段(选项卡)中包含谷歌地图,我似乎遇到了地图读取回调的问题,它说它未使用的导入语句。我所有的库都已编译,我已经同步了 gradle,但它仍然无法工作,我还是 android 新手,所以这不是我最擅长的领域。

下面是我的代码

package com.example.hp_user.shoutfinal28;



import android.os.Bundle;

import android.support.v4.app.Fragment;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;


import com.google.android.gms.maps.MapFragment;

import com.google.android.gms.maps.GoogleMap;

import com.google.android.gms.maps.OnMapReadyCallback;



public class FragmentShouts_Maps extends Fragment implements onMapReadyCallback { View view = inflater.inflate(R.layout.fragmentshouts_maps, container, false);
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Get the view from fragment shouts.xml
   return  inflater.inflate(R.layout.fragmentshouts_maps, container, false);

    MapFragment fragment = (MapFragment)getChildFragmentManager().findFragmentById(R.id.maps);
    fragment.getMapAsync(this);
}


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




}

@Override
public void onMapReady (GoogleMap googleMap)




}

这是我声明地图的 xml 文件

<RelativeLayout 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" >

<fragment android:id="@+id/maps"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.example.hp_user.shoutfinal28.FragmentShouts_Maps"
    android:layout_alignParentEnd="true">
</fragment>

</RelativeLayout>

【问题讨论】:

    标签: android google-maps android-studio


    【解决方案1】:

    上线

    public class FragmentShouts_Maps extends Fragment implements onMapReadyCallback { 
    

    onMapReadyCallback 首字母大写:OnMapReadyCallback

    PS:和你提到的错误无关,但你也得扛着这条线

    View view = inflater.inflate(R.layout.fragmentshouts_maps, container, false);
    

    到 onCreateView 方法的内部。

    【讨论】:

    • 谢谢你,它的工作,我也把它移到 onCreateView 并返回视图。 @ozlem
    • 现在我的 mapfragment 有问题,整行都说 incovertible type MapFragment fragment = (MapFragment)getChildFragmentManager().findFragmentById(R.id.maps); @Ozlem
    • 你能把定义R.id.maps的xml文件贴出来吗?
    • 因为“R.id.maps”是一个Fragment,但是您尝试将它分配给MapFragment。我不知道您到底想做什么,但您可以尝试像 stackoverflow.com/questions/15433820/… 中的 FragmentTransaction。
    • 我找到了在函数结束前返回视图的答案,因此跳过了 mapfragment 的代码行
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-15
    • 1970-01-01
    • 1970-01-01
    • 2017-08-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多