错误:类SupportMapFragment中的getMapAsync方法无法应用于给定类型;

时间:2018-09-03 07:55:22

标签: java

我收到此错误

  

错误:类SupportMapFragment中的方法getMapAsync不能为   适用于给定的类型;必需:找到OnMapReadyCallback:否   参数原因:实际和正式参数列表的长度不同

     

错误:无法访问zzbgl类文件   找不到com.google.android.gms.internal.zzbgl

     

在MapDirectionDisplayActivity.java文件中

这是我的代码

private void getLastActivityInfo() 
{
    lastActivityData = getIntent().getExtras();
}

private void setUpMapIfNeeded() {
    if (mapView == null) 
    {
        mapView = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
        if (mapView != null) 
        {
            CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(lastActivityData.getDouble("point_one_lat")
                    , lastActivityData.getDouble("point_one_lon")), 15);
            mapView.animateCamera(cameraUpdate);
        }
    }

    new DirectionLoadingThread().execute();
}


@Override
public void onBackPressed() {
    finish();
    super.onBackPressed();

}
@Override
protected void onResume() {

    try {
        if(gpsTracker!=null)
            gpsTracker.loctionUpdate();
    } catch (Exception e) {
    }
    super.onResume();
}
@Override
public void finish() {
    try {
        if(gpsTracker!=null)
        {
            gpsTracker.stopUsingGPS();
            gpsTracker.stopSelf();
        }

    } catch (Exception e) {
    }

    super.finish();
}
public class MyLocationListener implements LocationListener
{
    Context context;

    MyLocationListener(Context context)
    {
        this.context=context;
    }
    @Override
    public void onProviderDisabled(String provider)
    {
        Toast.makeText(context,"Gps Disabled",Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onProviderEnabled(String provider)
    {
        Toast.makeText(context,"Gps Enabled",Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras)
    {
    }

    @Override
    public void onLocationChanged(Location location)
    {
        double lat = location.getLatitude();
        double lng= location.getLongitude();
    }
}

private class DirectionLoadingThread extends AsyncTask<Void, Void, JSONArray>
{

    @Override
    protected JSONArray doInBackground(Void... arg0) {

        String apiUrl ="http://maps.googleapis.com/maps/api/directions/json?origin="+lastActivityData.getDouble("point_one_lat")+","+lastActivityData.getDouble("point_one_lon")
                +"&destination="+lastActivityData.getDouble("point_two_lat")
                +","+lastActivityData.getDouble("point_two_lon")+"&sensor=false";
                String result;
                try {
                    result  = CustomHttpClient.executeGet(apiUrl);
                    if(result!=null)
                    {
                        return new JSONObject(result).getJSONArray("routes").getJSONObject(0).getJSONArray("legs").getJSONObject(0).getJSONArray("steps");
                    }
                }catch (Exception e) {
                }
        return null;
    }

    @Override
    protected void onPostExecute(JSONArray resultArray) {
         if (mapView != null) 
            {
                mapView.addMarker(new MarkerOptions()
                .position(new LatLng(lastActivityData.getDouble("point_one_lat"), lastActivityData.getDouble("point_one_lon")))
                .title(lastActivityData.getString("point_location_one_title")));

                LatLng lastLonLat = new LatLng(lastActivityData.getDouble("point_one_lat"), lastActivityData.getDouble("point_one_lon"));
                if(resultArray!=null)
                {
                    LatLng newLonLat = null ;
                    for (int i = 0; i < resultArray.length(); i++) {

                        try {
                            newLonLat = new LatLng(resultArray.getJSONObject(i).getJSONObject("end_location").getDouble("lat")
                                    , resultArray.getJSONObject(i).getJSONObject("end_location").getDouble("lng"));
                            mapView.addPolyline(new PolylineOptions().add(lastLonLat
                            ,newLonLat)
                                    .width(3)
                                    .color(Color.BLUE));


                        } catch (JSONException e) {
                        }
                        lastLonLat = newLonLat;
                    }

                }

                mapView.addMarker(new MarkerOptions()
                .position(new LatLng(lastActivityData.getDouble("point_two_lat"), lastActivityData.getDouble("point_two_lon")))
                .title(lastActivityData.getString("point_location_two_title")));
            }
        super.onPostExecute(resultArray);
    }
}

0 个答案:

没有答案