本文整理汇总了Java中com.google.android.gms.location.LocationRequest.setNumUpdates方法的典型用法代码示例。如果您正苦于以下问题:Java LocationRequest.setNumUpdates方法的具体用法?Java LocationRequest.setNumUpdates怎么用?Java LocationRequest.setNumUpdates使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.location.LocationRequest
的用法示例。
在下文中一共展示了LocationRequest.setNumUpdates方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findImage
import com.google.android.gms.location.LocationRequest; //导入方法依赖的package包/类
private void findImage() {
LocationRequest request = LocationRequest.create();
request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
request.setNumUpdates(1);
request.setInterval(0);
try {
LocationServices.FusedLocationApi.requestLocationUpdates(mClient, request,
new LocationListener() {
@Override
public void onLocationChanged(Location location) {
Log.d(TAG, "onLocationChanged: " + location.getLatitude() + ", " +
location.getLongitude());
new SearchTask().execute(location);
}
});
} catch (SecurityException e) {
if (DEBUG) {
Log.e(TAG, "no permission", e);
}
}
}
示例2: findImage
import com.google.android.gms.location.LocationRequest; //导入方法依赖的package包/类
private void findImage() {
LocationRequest request = LocationRequest.create();
request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
request.setNumUpdates(1);
request.setInterval(0);
LocationServices.FusedLocationApi
.requestLocationUpdates(mClient, request, new LocationListener() {
@Override
public void onLocationChanged(Location location) {
Log.i(TAG, "Got a fix: " + location);
new SearchTask().execute(location);
}
});
}
示例3: findCoords
import com.google.android.gms.location.LocationRequest; //导入方法依赖的package包/类
private void findCoords() {
LocationRequest request = LocationRequest.create();
request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
request.setNumUpdates(1);
request.setInterval(0);
LocationServices.FusedLocationApi
.requestLocationUpdates(mClient, request, new LocationListener() {
@Override
public void onLocationChanged(Location location) {
double lat = location.getLatitude();
double lon = location.getLongitude();
mLocation.setLatitude(lat);
mLocation.setLongitude(lon);
mWasLocationFixed = true;
//Sort the order in which places are shown
//depending on how far they are from us (= by distance ascending)
Collections.sort(mPlaces, new Comparator<Visitable>() {
@Override
public int compare(Visitable a, Visitable b) {
Location aLoc = a.getLocation();
Location bLoc = b.getLocation();
return (int) aLoc.distanceTo(mLocation) - (int) bLoc.distanceTo(mLocation);
}
});
mAdapter.setPlaces(mPlaces);
mAdapter.notifyDataSetChanged();
}
});
}