的GetMap()未定义类型MapFragment [英] GetMap() undefined for the type MapFragment

查看:169
本文介绍了的GetMap()未定义类型MapFragment的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得一个地图片段中我的应用程序工作,我不断地得到一个错误试图让我的GoogleMap对象时。

  

MapFragment.java

 进口android.app.Fragment;
进口android.os.Bundle;
进口android.view.LayoutInflater;
进口android.view.View;
进口android.view.ViewGroup;

进口com.google.android.gms.maps.GoogleMap;
进口com.google.android.gms.maps.model.LatLng;

公共类MapFragment扩展片段{

私人GoogleMap的地图;

@覆盖
公共查看onCreateView(LayoutInflater充气,容器的ViewGroup,
        捆绑savedInstanceState){

    查看查看= inflater.inflate(R.layout.fragment_map,集装箱,假);

    地图=((MapFragment)getFragmentManager()findFragmentById(R.id.map)。)的GetMap()。

    返回查看;
    }
}
 

和我frament code是

  

fragment_map.xml

 < XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent>


    <按钮
    机器人:ID =@ + ID / btnEugene
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentRight =真
    机器人:layout_alignParentTop =真
    机器人:的onClick =onClick_Eugene
    机器人:文本=尤金/>

    <按钮
    机器人:ID =@ + ID / btnHpc
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentLeft =真
    机器人:layout_alignParentTop =真
    机器人:的onClick =onClick_HPC
    机器人:文本=HPC/>

    <按钮
    机器人:ID =@ + ID / btnTheGrove
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentTop =真
    机器人:layout_centerHorizo​​ntal =真
    机器人:的onClick =onClick_FG
    机器人:文本=森林树丛/>

    <片段
    机器人:ID =@ + ID /图
    机器人:名称=com.google.android.gms.maps.MapFragment
    机器人:layout_below =@ + ID / btnTheGrove
    机器人:重力=中心
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent/>

< / RelativeLayout的>
 

我得到确切的错误是

  

该方法的GetMap()是未定义的类型MapFragment

我是什么做错了吗?

解决方案

的GetMap()是德precated。尝试使用<一个href="http://developer.android.com/reference/com/google/android/gms/maps/MapFragment.html#getMapAsync(com.google.android.gms.maps.OnMa$p$padyCallback)"相对=nofollow> getMapAsync

编辑* 呵呵,也改变你的类名的东西不同, 进口 com.google.android.gms.maps.MapFragment 这是你应该在XML使用类和具有的GetMap()方法:)

I am trying to get a map fragment working within my application and I continue to get an error when trying to get my GoogleMap object.

MapFragment.java

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

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

public class MapFragment extends Fragment {

private GoogleMap map;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

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

    map  = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

    return view;
    }
}

And my frament code is

fragment_map.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >


    <Button
    android:id="@+id/btnEugene"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:onClick="onClick_Eugene"
    android:text="Eugene" />

    <Button
    android:id="@+id/btnHpc"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:onClick="onClick_HPC"
    android:text="HPC" />

    <Button
    android:id="@+id/btnTheGrove"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:onClick="onClick_FG"
    android:text="Forest Grove" />

    <fragment
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.MapFragment"
    android:layout_below="@+id/btnTheGrove"
    android:gravity="center"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</RelativeLayout>

The exact error I am getting is

The method getMap() is undefined for the type MapFragment

What am I doing wrong?

解决方案

getMap() is deprecated. Try using getMapAsync

EDIT* Oh, also change your class name to something different and import com.google.android.gms.maps.MapFragment which is the class you should use in the xml and has the getMap() method :)

这篇关于的GetMap()未定义类型MapFragment的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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