我正在制作YouTube教程(https://www.youtube.com/watch?v=gAIErOevfoA),我的地图运行良好,但它没有显示附近的位置。我注意到有一条线路通过GoogleApiClient
,并被告知它现在已更改为GoogleSignInOptions
。
我是安卓工作室的新手,所以我真的不知道如何在代码中实现新的方法。我试着把GoogleApiClient
改成GoogleSignInOptions
,但现在出现了更多的错误,我不想把我的错误搞砸。
这是包含错误的Java文件,我已经把它缩短了一点,我还在if语句if (mGoogleApiClient.isConnected()) {...}
上得到了一个错误
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, GoogleApiClient.ConnectionCallbacks,
GoogleSignInOptions.OnConnectionFailedListener, LocationListener {
private GoogleMap mMap;
GoogleSignInOptions mGoogleApiClient;
double currentLatitude, currentLongitude;
Location myLocation;
private final static int REQUEST_CHECK_SETTINGS_GPS = 0x1;
private final static int REQUEST_ID_MULTIPLE_PERMISSIONS = 0x2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
setUPGClient();
}
private void setUPGClient() {
mGoogleApiClient = new GoogleSignInOptions.Builder(this)
.enableAutoManage(this, 0, this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
mGoogleApiClient.connect();
}
}
在此处查看迁移指南https://android-developers.googleblog.com/2017/11/moving-past-googleapiclient_21.html