【问题标题】:getmap() is deprecated and use getmapAsync? [duplicate]getmap() 已弃用并使用 getmapAsync? [复制]
【发布时间】:2016-07-31 12:38:48
【问题描述】:

我正在使用 android studio 制作预订应用程序。我在其中添加了一个地图片段,但我收到错误消息 getmap() 已弃用,我想改用 getMapAsync()。我试过了,但出现了更多错误。请帮帮我。谢谢。

public class HomeActivity  extends Fragment implements View.OnClickListener,GoogleApiClient.ConnectionCallbacks,GoogleApiClient.OnConnectionFailedListener,GoogleMap.OnMapClickListener,GoogleMap.OnMarkerDragListener,{
private GoogleMap map;
private static View v;
private GoogleApiClient mGoogleApiClient;
double latitude,longitude;
boolean centeronCurrent= true, syncWithServer= true, trackDriverBoolean= true, waitForRideToEnd=true;
TextView selectPickup, statusText;
Button requesttaxi;
LatLng currentLocation;
int shortestTime;
int nearbyTaxis,taxicount;
String driverid="", currentRideid="";
ArrayList<Marker> markers= new ArrayList<Marker>();


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

    if (v!= null){
        ViewGroup parent= (ViewGroup) v.getParent();
        if (parent!= null)
            parent.removeView(v);
    }
    try {
        v= inflater.inflate(R.layout.home,container,false);
    }
    catch (InflateException e){
        e.printStackTrace();
    }
    map= ((SupportMapFragment)getChildFragmentManager().findFragmentById(R.id.map)).getMap();
    map.setMyLocationEnabled(true);

    map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    map.setOnMapClickListener(this);
    map.setOnMarkerDragListener(this);

    requesttaxi= (Button) v.findViewById(R.id.request_taxi);
    requesttaxi.setOnClickListener(this);
    statusText=(TextView) v.findViewById(R.id.status_text);
    statusText.setVisibility(View.INVISIBLE);

    SharedPreferences sp = getActivity().getSharedPreferences("Session", Context.MODE_PRIVATE);
    SharedPreferences.Editor editor;
    editor=sp.edit();
    String location= sp.getString("location","");

    mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(LocationServices.API)
            .build();

    selectPickup= (TextView) v.findViewById(R.id.select_location);
    selectPickup.setOnClickListener(this);
    if (location.equals(""))
    {
        selectPickup.setText("Select Pick up Location");
    }
    else {
        String latstr= sp.getString("locationlat","");
        String longstr= sp.getString("locationlong","");
        latitude= Double.parseDouble(latstr);
        longitude= Double.parseDouble(longstr);
        selectPickup.setText(location);

        editor.putString("location","");
        editor.putString("locationlat","");
        editor.putString("locationlong","");
        editor.commit();
        centeronCurrent=false;
    }

    mGoogleApiClient.connect();
    return v;

}

【问题讨论】:

  • 你的错误是什么?请张贴你的logcat!

标签: android android-studio


【解决方案1】:

您的地图片段类必须实现OnMapReadyCallback 并覆盖onMapReady()

与本文相关:Replace getMap with getMapAsync

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-01
    • 1970-01-01
    • 2018-10-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多