本文整理汇总了Java中com.google.android.gms.awareness.snapshot.LocationResult类的典型用法代码示例。如果您正苦于以下问题:Java LocationResult类的具体用法?Java LocationResult怎么用?Java LocationResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LocationResult类属于com.google.android.gms.awareness.snapshot包,在下文中一共展示了LocationResult类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onMapReady
import com.google.android.gms.awareness.snapshot.LocationResult; //导入依赖的package包/类
@Override
public void onMapReady(final GoogleMap googleMap) {
googleMap.getUiSettings().setAllGesturesEnabled(false);
googleMap.setMaxZoomPreference(20.0f);
googleMap.setMinZoomPreference(10.0f);
final LatLng[] currentLocation = new LatLng[1];
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
Awareness.SnapshotApi.getLocation(awarenessApiClient)
.setResultCallback(new ResultCallback<LocationResult>() {
@Override
public void onResult(@NonNull LocationResult locationResult) {
if (!locationResult.getStatus().isSuccess()) {
Log.e("", "Could not get location.");
return;
}
Location location = locationResult.getLocation();
currentLocation[0] = new LatLng(location.getLatitude(), location.getLongitude());
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(currentLocation[0], 12.0f));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(16.0f), 3000, null);
}
});
}
示例2: getLocation
import com.google.android.gms.awareness.snapshot.LocationResult; //导入依赖的package包/类
/**
* Get user's current location. We are also displaying Google Static map.
*/
@RequiresPermission("android.permission.ACCESS_FINE_LOCATION")
private void getLocation() {
//noinspection MissingPermission
Awareness.SnapshotApi.getLocation(mGoogleApiClient)
.setResultCallback(new ResultCallback<LocationResult>() {
@Override
public void onResult(@NonNull LocationResult locationResult) {
if (!locationResult.getStatus().isSuccess()) {
Toast.makeText(SnapshotApiActivity.this, "Could not get location.", Toast.LENGTH_LONG).show();
return;
}
//get location
Location location = locationResult.getLocation();
((TextView) findViewById(R.id.current_latlng)).setText(location.getLatitude() + ", " + location.getLongitude());
//display the time
TextView timeTv = (TextView) findViewById(R.id.latlng_time);
SimpleDateFormat sdf = new SimpleDateFormat("h:mm a dd-MM-yyyy", Locale.getDefault());
timeTv.setText("as on: " + sdf.format(new Date(location.getTime())));
//Load the current map image from Google map
String url = "https://maps.googleapis.com/maps/api/staticmap?center="
+ location.getLatitude() + "," + location.getLongitude()
+ "&zoom=20&size=400x250&key=" + getString(R.string.api_key);
Picasso.with(SnapshotApiActivity.this).load(url).into((ImageView) findViewById(R.id.current_map));
}
});
}
示例3: createRequest
import com.google.android.gms.awareness.snapshot.LocationResult; //导入依赖的package包/类
@Override
@RequiresPermission("android.permission.ACCESS_FINE_LOCATION")
protected PendingResult<LocationResult> createRequest(GoogleApiClient googleApiClient) {
return Awareness.SnapshotApi.getLocation(googleApiClient);
}
示例4: unwrap
import com.google.android.gms.awareness.snapshot.LocationResult; //导入依赖的package包/类
@Override
protected Location unwrap(LocationResult result) {
return result.getLocation();
}