本文整理汇总了Java中android.location.LocationManager.GPS_PROVIDER属性的典型用法代码示例。如果您正苦于以下问题:Java LocationManager.GPS_PROVIDER属性的具体用法?Java LocationManager.GPS_PROVIDER怎么用?Java LocationManager.GPS_PROVIDER使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.location.LocationManager
的用法示例。
在下文中一共展示了LocationManager.GPS_PROVIDER属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: provide
@Override
protected void provide() {
Looper.prepare();
locationManager = (LocationManager) this.getContext().getSystemService(Context.LOCATION_SERVICE);
locationListener = new MyLocationListener();
long minTime = 0;
float minDistance = 0;
String provider;
if (Geolocation.LEVEL_EXACT.equals(level)) {
provider = LocationManager.GPS_PROVIDER;
}
else {
provider = LocationManager.NETWORK_PROVIDER;
}
locationManager.requestLocationUpdates(provider, minTime, minDistance, locationListener);
Looper.loop();
}
示例2: provide
@Override
protected void provide() {
Looper.prepare();
locationManager = (LocationManager) this.getContext().getSystemService(Context.LOCATION_SERVICE);
locationListener = new MyLocationListener();
long minTime = this.interval;
float minDistance = 0;
String provider;
if (Geolocation.LEVEL_EXACT.equals(level)) {
provider = LocationManager.GPS_PROVIDER;
}
else {
provider = LocationManager.NETWORK_PROVIDER;
}
locationManager.requestLocationUpdates(provider, minTime, minDistance, locationListener);
Looper.loop();
}
示例3: testSave
public void testSave() {
Location l = new Location(LocationManager.GPS_PROVIDER);
l.setLatitude(1.0);
l.setLongitude(2.0);
BlankModel b = new BlankModel();
b.setLocation(l);
b.save(getContext());
BlankModel b2 = Model.objects(getContext(), BlankModel.class).get(b.getId());
Location l2 = b2.getLocation();
assertEquals(1.0, l2.getLatitude());
assertEquals(2.0, l2.getLongitude());
}
示例4: setLocation
/**
* GPS定位需要不停的刷新经纬度值
*/
private static void setLocation(double latitude, double longitude) throws Exception{
try {
String providerStr = LocationManager.GPS_PROVIDER;
Location mockLocation = new Location(providerStr);
mockLocation.setLatitude(latitude);
mockLocation.setLongitude(longitude);
mockLocation.setAltitude(0); // 高程(米)
mockLocation.setBearing(0); // 方向(度)
mockLocation.setSpeed(0); //速度(米/秒)
mockLocation.setAccuracy(2); // 精度(米)
mockLocation.setTime(System.currentTimeMillis()); // 本地时间
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
//api 16以上的需要加上这一句才能模拟定位 , 也就是targetSdkVersion > 16
mockLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
}
locationManager.setTestProviderLocation(providerStr, mockLocation);
} catch (Exception e) {
// 防止用户在软件运行过程中关闭模拟位置或选择其他应用
stopMockLocation();
throw e;
}
}
示例5: toSysLocation
public Location toSysLocation() {
Location location = new Location(LocationManager.GPS_PROVIDER);
location.setAccuracy(8f);
Bundle extraBundle = new Bundle();
location.setBearing(bearing);
Reflect.on(location).call("setIsFromMockProvider", false);
location.setLatitude(latitude);
location.setLongitude(longitude);
location.setSpeed(speed);
location.setTime(System.currentTimeMillis());
location.setExtras(extraBundle);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
location.setElapsedRealtimeNanos(277000000);
}
int svCount = VirtualGPSSatalines.get().getSvCount();
extraBundle.putInt("satellites", svCount);
extraBundle.putInt("satellitesvalue", svCount);
return location;
}
示例6: onCreate
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LogHelper.verboseLog(TAG,
"File name: \"" +
Thread.currentThread().getStackTrace()[2].getFileName() +
"\", Line number: " +
Thread.currentThread().getStackTrace()[2].getLineNumber() +
", Class name: \"" +
Thread.currentThread().getStackTrace()[2].getClassName() +
"\", Method name: \"" +
Thread.currentThread().getStackTrace()[2].getMethodName() +
"\"");
if (Configuration.sIsFeatureLocationAvailable) {
if (Configuration.sIsFeatureLocationNetworkAvailable) {
mNetworkProvider = LocationManager.NETWORK_PROVIDER;
}
if (Configuration.sIsFeatureLocationGpsAvailable) {
mGpsProvider = LocationManager.GPS_PROVIDER;
}
mPassiveProvider = LocationManager.PASSIVE_PROVIDER;
}
}
示例7: getLocation
/**
* @return the location this event occurred at if it exists, or null otherwise
*/
public Location getLocation() {
if (latitude == INVALID_LATLONG)
return null;
Location location = new Location(LocationManager.GPS_PROVIDER);
location.setLatitude(latitude);
location.setLongitude(longitude);
return location;
}
示例8: getLocation
public void getLocation(Fragment fragment) {
this.fragment = fragment;
boolean locationPermissionFlag = util.checkPermission(locationPermissions,
activity);
if (locationPermissionFlag) {
fragment.requestPermissions(locationPermissions, Configure.LOCATION_PERMISSION_CODE);
}else{
locationManager = (LocationManager) activity.getSystemService(Context.
LOCATION_SERVICE);
String provider;
List<String> providerList = locationManager.getProviders(true);
if (providerList.contains(LocationManager.GPS_PROVIDER)) {
provider = LocationManager.GPS_PROVIDER;
} else if (providerList.contains(LocationManager.NETWORK_PROVIDER)) {
provider = LocationManager.NETWORK_PROVIDER;
} else {
Toast.makeText(activity, "请连接网络或打开GPS",
Toast.LENGTH_LONG).show();
return;
}
Location location = locationManager.getLastKnownLocation(provider);
locationManager.requestLocationUpdates(provider, 2000, 10, this);
if (location != null) {
getLocation(location);
}
}
}
示例9: getLocation
@NonNull
public static Location getLocation(@NonNull LatLng latitudeLongitude) {
Location location = new Location(LocationManager.GPS_PROVIDER);
location.setLatitude(latitudeLongitude.latitude);
location.setLongitude(latitudeLongitude.longitude);
return location;
}
示例10: activateTracking
private void activateTracking(){
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.
Log.e(TAG, "No permissions to access the GPS location!");
assert(false);
return;
}
trackingActive = true;
final String PROVIDER = LocationManager.GPS_PROVIDER;
if(!manager.isProviderEnabled(PROVIDER)){
// TODO: start dialog to enable GPS
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.gps_disabled);
builder.setMessage(R.string.ask_to_enable_gps);
builder.setCancelable(true);
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
manager.requestLocationUpdates(PROVIDER, 0, 0, listener);
Button button = findViewById(R.id.toggleTracking);
button.setText(R.string.stopTracking);
}
示例11: initLocation
private void initLocation() {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
List<String> providers = mLocationManager.getProviders(true);
String locationProvider;
/**
* 如果首选GPS定位,会存在这种情况,上次GPS启动采集数据在A地,本次在B地需要定位,但用户恰好在室内无
* GPS信号,只好使用上次定位数据,就出现了地区级偏差。而网络定位则更具有实时性,在精度要求不高以及室内
* 使用场景更多的前提下,首选网络定位
*/
if (providers.contains(LocationManager.NETWORK_PROVIDER)) {
locationProvider = LocationManager.NETWORK_PROVIDER; // 首选网络定位
} else if (providers.contains(LocationManager.GPS_PROVIDER)) {
locationProvider = LocationManager.GPS_PROVIDER;
} else {
locationProvider = LocationManager.PASSIVE_PROVIDER;
}
if (mLocationListener != null)
mLocationManager.requestLocationUpdates(locationProvider, 2000, 10, mLocationListener);
}
示例12: set
@Override
public void set(Cursor c, String fieldName) {
double lat = c.getDouble(c.getColumnIndexOrThrow(latName(fieldName)));
double lng = c.getDouble(c.getColumnIndexOrThrow(lngName(fieldName)));
Location l = new Location(LocationManager.GPS_PROVIDER);
l.setLatitude(lat);
l.setLongitude(lng);
mValue = l;
}
示例13: initLocationManager
/**
* 配置LocationManger参数
*/
public static void initLocationManager() throws Exception{
if (canMockPosition && !hasAddTestProvider) {
try {
String providerStr = LocationManager.GPS_PROVIDER;
LocationProvider provider = locationManager.getProvider(providerStr);
if (provider != null) {
locationManager.addTestProvider(
provider.getName()
, provider.requiresNetwork()
, provider.requiresSatellite()
, provider.requiresCell()
, provider.hasMonetaryCost()
, provider.supportsAltitude()
, provider.supportsSpeed()
, provider.supportsBearing()
, provider.getPowerRequirement()
, provider.getAccuracy());
} else {
locationManager.addTestProvider(
providerStr
, true, true, false, false, true, true, true
, Criteria.POWER_HIGH
, Criteria.ACCURACY_FINE);
}
locationManager.setTestProviderEnabled(providerStr, true);
locationManager.requestLocationUpdates(providerStr, 0, 0, new LocationStatuListener());
locationManager.setTestProviderStatus(providerStr, LocationProvider.AVAILABLE, null, System.currentTimeMillis());
Log.i(TAG,"already open GPS!");
// 模拟位置可用
hasAddTestProvider = true;
Log.d(TAG, "hasAddTestProvider:" + hasAddTestProvider);
canMockPosition = true;
} catch (Exception e) {
canMockPosition = false;
Log.d(TAG, "初始化异常:" + e);
throw e;
}
}
}
示例14: setUpMap
@SuppressWarnings({"MissingPermission"})
private void setUpMap() {
mMap.setMyLocationEnabled(true);
// mMap.setPadding(0, ConversionUtil.dpToPx(68, getResources()), 0, 0);
mMap.getUiSettings().setMyLocationButtonEnabled(false);
mMap.getUiSettings().setCompassEnabled(false);
if(mPlaceToEdit == null) {
moveCameraToLastKnownLocation(); //If creating a new place, go to user current location
mRadius.setProgress(1);
mRadiusDisplay.setText("100 m");
//SnackbarUtil.showSnackbar(mMapContainer, SnackbarUtil.SnackbarType.NOTICE, R.string.activity_place_snackbar_help, SnackbarUtil.SnackbarDuration.SHORT, null);
} else {
drawMarkerWithCircle(new LatLng(mPlace.getLatitude(), mPlace.getLongitude()), mPlace.getRadius()); //If editing a place, go to that place and add a marker, circle
Location loc = new Location(LocationManager.GPS_PROVIDER);
loc.setLatitude(mPlace.getLatitude());
loc.setLongitude(mPlace.getLongitude());
moveCameraToLocation(loc);
TransitionManager.beginDelayedTransition(mMapContainer, new Slide(Gravity.BOTTOM));
mAlias.setText(mPlace.getAlias());
mAddress.setText(mPlace.getAddress());
mAliasAddressContainer.setVisibility(View.VISIBLE);
mAliasAddressAlreadySet = true;
mRadius.setProgress(mPlace.getRadius()/100 -1 );
mRadiusDisplay.setText(String.valueOf(mPlace.getRadius()) + " m");
}
}
示例15: scheduleMockGps
private void scheduleMockGps(final Context context) {
Gps gps;
synchronized (mMockGps) {
gps = mMockGps[0];
}
if (null == gps) {
return;
}
if (!Macro.RealGps) {
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
Location location = new Location(LocationManager.GPS_PROVIDER);
location.setLatitude(gps.mLatitude);
location.setLongitude(gps.mLongitude);
location.setAltitude(0);
location.setBearing(0);
location.setSpeed(0);
location.setAccuracy(2);
location.setTime(System.currentTimeMillis());
location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
locationManager.setTestProviderLocation(LocationManager.GPS_PROVIDER, location);
}
new Handler(context.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
scheduleMockGps(context);
}
}, 1000);
}