本文整理了Java中com.google.android.gms.location.FusedLocationProviderApi.getLastLocation()
方法的一些代码示例,展示了FusedLocationProviderApi.getLastLocation()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FusedLocationProviderApi.getLastLocation()
方法的具体详情如下:
包路径:com.google.android.gms.location.FusedLocationProviderApi
类名称:FusedLocationProviderApi
方法名:getLastLocation
暂无
代码示例来源:origin: commonsguy/cw-omnibus
@SuppressWarnings("MissingPermission")
@Override
public void run() {
Location location=
LocationServices.FusedLocationApi.getLastLocation(getPlayServices());
if (location==null) {
getListView().postDelayed(this, 1000);
}
else {
fetchForecast(location);
}
}
代码示例来源:origin: palaima/DebugDrawer
/**
* Get last known location
*
* @return Location
*/
Location getLastLocation() {
return LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
}
代码示例来源:origin: yayaa/LocationManager
@SuppressWarnings("ResourceType")
Location getLastLocation() {
return LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
}
代码示例来源:origin: lycha/augmented-reality-example
@Override
public void onLocationChanged(Location location) {
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
mGoogleApiClient);
if (mLastLocation != null) {
onLocationChangedListener.onLocationChanged(mLastLocation);
}
}
}
代码示例来源:origin: adafruit/Bluefruit_LE_Connect_Android
@Override
public void onConnected(Bundle bundle) {
Log.d(TAG, "Google Play Services connected");
// Location updates should have already been granted to scan for bluetooth peripherals, so we dont ask for them again
try {
setLastLocation(LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient));
} catch (SecurityException e) {
Log.e(TAG, "Security exception requesting location updates: " + e);
}
}
代码示例来源:origin: domsu/compass
private void emitLastKnownLocation() {
Location lastLocation = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
if (lastLocation != null)
emitData(lastLocation);
}
代码示例来源:origin: livroandroid/5ed
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_my_location:
// Última localização
Location l = LocationServices.FusedLocationApi.getLastLocation(
mGoogleApiClient);
Log.d(TAG, "lastLocation: " + l);
// Atualiza a localização do mapa
setMapLocation(l);
return true;
}
return super.onOptionsItemSelected(item);
}
代码示例来源:origin: ankitdubey021/GPSTracker
@Override
public void onConnected(@Nullable Bundle bundle) {
Log.i("My Tracker", "Location services connected!.");
if (ActivityCompat.checkSelfPermission(ctx, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(ctx, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
Location location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
fetchLocation(location);
if (location == null) {
if (ActivityCompat.checkSelfPermission(ctx, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(ctx, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
}
}
代码示例来源:origin: jakehilborn/speedr
@Override
@SuppressWarnings("MissingPermission")
public void onConnected(Bundle bundle) {
Crashlytics.log(Log.INFO, SettingsActivity.class.getSimpleName(), "Coverage map with location");
String uri;
Location lastLocation = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
if (lastLocation != null) {
uri = "http://product.itoworld.com/map/124?lat=" + lastLocation.getLatitude() + "&lon=" + lastLocation.getLongitude() + "&zoom=14";
} else {
uri = mapOfUnitedStates;
}
launchWebpage(uri);
googleApiClient.disconnect();
}
代码示例来源:origin: safetysystemtechnology/location-tracker-background
@Override
public void onConnected(Bundle connectionHint) throws SecurityException {
Log.i(TAG, "Connected to GoogleApiClient");
if (mCurrentLocation == null) {
mCurrentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
updateService();
}
startLocationUpdates();
}
代码示例来源:origin: WomenWhoCode/WomenWhoCode
@Override
public void onConnected(Bundle bundle) {
Log.i(TAG, "Location services connected.");
Location mCurrentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
if (mCurrentLocation == null) {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
} else {
mLocationCallback.handleNewLocation(mCurrentLocation);
}
}
代码示例来源:origin: nglauber/dominando_android2
private void obterUltimaLocalizacao() {
Log.d("NGVL", "obterUltimaLocalizacao::BEGIN");
Location location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
if (location != null) {
mTentativas = 0;
mOrigem = new LatLng(location.getLatitude(), location.getLongitude());
atualizarMapa();
} else if (mTentativas < 10){ // vamos tentar obter a última localização 10 vezes
mTentativas++;
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
obterUltimaLocalizacao();
}
}, 2000); // a cada 2 segundos
}
Log.d("NGVL", "obterUltimaLocalizacao::END");
}
private void atualizarMapa() {
代码示例来源:origin: florent37/RxGps
@Override
protected void onGoogleApiClientReady(GoogleApiClient apiClient, MaybeEmitter<Location> emitter) {
//noinspection MissingPermission
Location location = LocationServices.FusedLocationApi.getLastLocation(apiClient);
if (location != null) {
emitter.onSuccess(location);
} else {
emitter.onComplete();
}
}
}
代码示例来源:origin: lycha/augmented-reality-example
@Override
public void onConnected(Bundle bundle) {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
mGoogleApiClient);
if (mLastLocation != null) {
onLocationChangedListener.onLocationChanged(mLastLocation);
}
}
代码示例来源:origin: j4velin/MapsMeasure
@Override
public void onConnected(final Bundle bundle) {
//noinspection ResourceType
Location l = LocationServices.FusedLocationApi
.getLastLocation(mGoogleApiClient);
mGoogleApiClient.disconnect();
callback.gotLocation(l);
}
代码示例来源:origin: klaasnotfound/LocationAssistant
protected void checkInitialLocation() {
if (!googleApiClient.isConnected() || !permissionGranted || !locationRequested || !locationStatusOk) return;
try {
Location location = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
onLocationChanged(location);
} catch (SecurityException e) {
if (!quiet)
Log.e(getClass().getSimpleName(), "Error while requesting last location:\n " +
e.toString());
if (listener != null)
listener.onError(ErrorType.RETRIEVAL, "Could not retrieve initial location:\n" +
e.getMessage());
}
}
代码示例来源:origin: CUTR-at-USF/OpenTripPlanner-for-Android
/**
* Returns last location coordinates.
* <p>
* This is obtained from the Location Client if it's connected and returns
* a valid Location. If not saved last location is provided.
* <p>
* On successful call to Location Client saved last location is updated.
*
* @return a LatLng object with the most updated user coordinates
*/
public LatLng getLastLocation() {
if (mGoogleApiClient != null) {
if (mGoogleApiClient.isConnected()) {
Location loc = FusedLocationApi.getLastLocation(mGoogleApiClient);
if (loc != null) {
LatLng mCurrentLocation = new LatLng(loc.getLatitude(), loc.getLongitude());
mSavedLastLocation = mCurrentLocation;
return mCurrentLocation;
}
}
if (mSavedLastLocation != null) {
return mSavedLastLocation;
}
}
return null;
}
代码示例来源:origin: AlexZhuo/AlxLocationManager
/**
* 拿到最近一次的硬件经纬度记录,只用精确度足够高的时候才会采用这种定位
* @return
*/
public boolean getCurrentLocation(){
Location mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
Log.i("AlexLocation","得到last Location的gps是=="+mLastLocation);
if (mLastLocation == null) return false;//在少数情况下这里有可能是null
double latitude = mLastLocation.getLatitude();//纬度
double longitude = mLastLocation.getLongitude();//经度
double altitude = mLastLocation.getAltitude();//海拔
float last_accuracy = mLastLocation.getAccuracy();//精度
Log.i("AlexLocation","last Location的精度是"+last_accuracy);
String provider = mLastLocation.getProvider();//传感器
float bearing = mLastLocation.getBearing();
float speed = mLastLocation.getSpeed();//速度
if(isDebugging)Toast.makeText(context,"获取到last location经纬度 "+"纬度"+latitude+" 经度"+longitude+ "精确度"+last_accuracy,Toast.LENGTH_LONG).show();
Log.i("AlexLocation","获取last location成功,纬度=="+latitude+" 经度"+longitude+" 海拔"+altitude+" 传感器"+provider+" 速度"+speed+ "精确度"+last_accuracy);
if(last_accuracy < MAX_deviation){
recordLocation(context,latitude,longitude,last_accuracy);
}else {
Log.i("AlexLocation","精确度太低,放弃last Location");
}
return last_accuracy < MAX_deviation;
}
代码示例来源:origin: AppLozic/Applozic-Android-SDK
@Override
public void onConnected(Bundle bundle) {
try {
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;
}
mCurrentLocation = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
if (mCurrentLocation == null) {
Toast.makeText(this, R.string.waiting_for_current_location, Toast.LENGTH_SHORT).show();
locationRequest = new LocationRequest();
locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
locationRequest.setInterval(UPDATE_INTERVAL);
locationRequest.setFastestInterval(FASTEST_INTERVAL);
LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this);
}
if (mCurrentLocation != null) {
mapFragment.getMapAsync(this);
}
} catch (Exception e) {
e.printStackTrace();
}
}
代码示例来源:origin: AppLozic/Applozic-Android-SDK
@Override
public void onConnected(Bundle bundle) {
try {
Location mCurrentLocation = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
if (mCurrentLocation == null) {
Toast.makeText(this, R.string.waiting_for_current_location, Toast.LENGTH_SHORT).show();
locationRequest = new LocationRequest();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(UPDATE_INTERVAL);
locationRequest.setFastestInterval(FASTEST_INTERVAL);
LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this);
}
if (mCurrentLocation != null && conversation != null) {
conversation.attachLocation(mCurrentLocation);
}
} catch (Exception e) {
}
}
内容来源于网络,如有侵权,请联系作者删除!