为什么在以下代码中实现接口“onmapreadycallback”时出错?

时间:2016-01-14 06:33:42

标签: java android

错误在:

  

“公共类MapsActivity扩展FragmentActivity实现OnMapReadyCallback”

它以红色下划线,表示我声明我的类“抽象”或实现抽象方法。

提示说我可以实现这个方法。 这是什么意思?

    package autogenie.map;

    import android.Manifest;
    import android.app.Activity;
    import android.content.pm.PackageManager;
    import android.location.Location;
    import android.support.v4.app.ActivityCompat;
    import android.support.v4.app.FragmentActivity;
    import android.os.Bundle;

    import com.google.android.gms.common.api.GoogleApiClient;
    import com.google.android.gms.location.LocationServices;
    import com.google.android.gms.maps.CameraUpdateFactory;
    import com.google.android.gms.maps.GoogleMap;
    import com.google.android.gms.maps.OnMapReadyCallback;
    import com.google.android.gms.maps.SupportMapFragment;
    import com.google.android.gms.maps.model.LatLng;
    import com.google.android.gms.maps.model.MarkerOptions;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;
GoogleApiClient mGoogleApiClient;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);


    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(this);
    mGoogleApiClient = builder.build();

    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return;
    }
    Location mLastLocation = LocationServices.FusedLocationApi
            .getLastLocation(mGoogleApiClient);



    }

1 个答案:

答案 0 :(得分:0)

您的MapsActivity声明implements OnMapReadyCallback,但事实并非如此。

在下方添加MapsActivity

@Override
public void onMapReady(GoogleMap googleMap) {
    // Your code here
}