【发布时间】:2018-09-07 14:25:52
【问题描述】:
我正在构建一个跟踪订单来源以交付包裹的类,我收到一条错误消息,指出FusedLocationProviderApi 已弃用,现在看来我必须改用FusedLocationProviderClient,当我申请FusedLocationProviderApi 时我也实现了 LocationListener 和 ConnectionCallback 和 GoogleaApiClient 我认为应该删除。
我怎样才能在这里实现这个
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tracking_order);
if(ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
{
requestRuntimePermission();
}
else
{
if (checkPlayServices())
{
buildGoogleApiClient();
createLocationRequest();
}
}
displayLocation();
}
private void displayLocation() {
if(ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
{
requestRuntimePermission();
}
else
{
mLastLocation = LocationServices.fused(null).getLastLocation(mGoogleApiClient);
if (mLastLocation != null)
{
double latitude = mLastLocation.getLatitude();
double longitude = mLastLocation.getLongitude();
LatLng yourLocation = new LatLng(latitude,longitude);
mMap.addMarker(new MarkerOptions().position(yourLocation).title("Tu ubicacion"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(yourLocation));
mMap.animateCamera(CameraUpdateFactory.zoomTo(17.0f));
}
else
{
Toast.makeText(this, "No se pudo obtener ubicacion", Toast.LENGTH_SHORT).show();
}
}
}
【问题讨论】:
标签: locationlistener fusedlocationproviderapi android-fusedlocation fusedlocationproviderclient