当前位置: 首页 > news >正文

建站用帝国还是wordpress做水电到哪个网站找信息

建站用帝国还是wordpress,做水电到哪个网站找信息,网站建设7个主要流程图,建立自己的WordPress主题文章目录 Android 系统定位和高德定位系统定位工具类封装LocationManager使用 高德定位封装高德地图使用 Android 系统定位和高德定位 系统定位 工具类 public class LocationUtils {public static final int REQUEST_LOCATION 0xa1;/*** 判断定位服务是否开启*/public sta…

文章目录

  • Android 系统定位和高德定位
    • 系统定位
      • 工具类
      • 封装LocationManager
      • 使用
    • 高德定位
      • 封装高德地图
      • 使用

Android 系统定位和高德定位

系统定位

工具类

public class LocationUtils {public static final int REQUEST_LOCATION = 0xa1;/*** 判断定位服务是否开启*/public static boolean isOpenLocationServer(Context context) {int locationMode = 0;try {locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE);} catch (Settings.SettingNotFoundException e) {e.printStackTrace();return false;}return locationMode != Settings.Secure.LOCATION_MODE_OFF;}/*** 判断GPS是否可用*/public static boolean isGPSEnabled(Context context) {LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);return manager.isProviderEnabled(LocationManager.GPS_PROVIDER);}/*** 判断定位是否可用*/public static boolean isLocationEnabled(Context context) {LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);return manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) || manager.isProviderEnabled(LocationManager.GPS_PROVIDER);}/*** 开启位置服务*/public static void openLocation(Activity activity) {activity.startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), REQUEST_LOCATION);}/*** 开启位置服务*/public static void openLocation(Fragment fragment) {fragment.startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), REQUEST_LOCATION);}}

封装LocationManager

public class LocationHelper {private static OnLocationChangeListener mOnLocationChangeListener;private static MyLocationListener mLocationListener;private static LocationManager mLocationManager;private static String mProvider;/*** 注册*/public static void registerLocation(Context context, @Nullable OnLocationChangeListener listener) {mOnLocationChangeListener = listener;mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);mProvider = mLocationManager.getBestProvider(getCriteria(), true);Location lastKnownLocation = mLocationManager.getLastKnownLocation(mProvider);if (listener != null && lastKnownLocation != null) {listener.onLastKnownLocation(lastKnownLocation);}mLocationListener = new MyLocationListener();startLocation();}/*** 开始定位*/public static void startLocation() {// 第二个参数:更新定位的时间间隔,第三个参数:更新定位的距离范围mLocationManager.requestLocationUpdates(mProvider, 0, 0, mLocationListener);}/*** 停止定位*/public static void stopLocation() {mLocationManager.removeUpdates(mLocationListener);}/*** 设置定位参数** @return {@link Criteria}*/private static Criteria getCriteria() {Criteria criteria = new Criteria();// 设置定位精确度 Criteria.ACCURACY_COARSE比较粗略,Criteria.ACCURACY_FINE则比较精细criteria.setAccuracy(Criteria.ACCURACY_FINE);// 设置是否要求速度criteria.setSpeedRequired(false);// 设置是否允许运营商收费criteria.setCostAllowed(false);// 设置是否需要方位信息criteria.setBearingRequired(false);// 设置是否需要海拔信息criteria.setAltitudeRequired(false);// 设置对电源的需求criteria.setPowerRequirement(Criteria.POWER_LOW);return criteria;}/*** 取消注册*/public static void unregisterLocation() {if (mLocationManager != null) {if (mLocationListener != null) {mLocationManager.removeUpdates(mLocationListener);}}mLocationManager = null;mLocationListener = null;mOnLocationChangeListener = null;}public interface OnLocationChangeListener {void onLastKnownLocation(Location location);void onLocationChanged(Location location);}public static class MyLocationListener implements LocationListener {@Overridepublic void onLocationChanged(@NonNull Location location) {if (mOnLocationChangeListener != null) {mOnLocationChangeListener.onLocationChanged(location);}}}
}
public class LocationService extends Service {public static void actionStart(Context context) {context.startService(new Intent(context, LocationService.class));}public static void actionStop(Context context) {context.stopService(new Intent(context, LocationService.class));}@SuppressLint("MissingPermission")@Overridepublic void onCreate() {super.onCreate();new Thread(() -> {Looper.prepare();LocationHelper.registerLocation(getApplicationContext(), new LocationHelper.OnLocationChangeListener() {@Overridepublic void onLastKnownLocation(Location location) {if (location != null) {Log.e("TAG", "onLastKnownLocation= " + location);}}@Overridepublic void onLocationChanged(Location location) {if (location != null) {Log.e("TAG", "onLocationChanged= " + location);stopSelf();}}});Looper.loop();}).start();}@Nullable@Overridepublic IBinder onBind(Intent intent) {return null;}@Overridepublic void onDestroy() {super.onDestroy();LocationHelper.unregisterLocation();}
}

使用

// 开始定位
LocationService.actionStart(MainActivity.this, "start");// 停止定位
LocationService.actionStart(MainActivity.this, "stop");// 单次定位
LocationService.actionStart(MainActivity.this, "once");

高德定位

封装高德地图

public class GDLocationHelper {private static AMapLocationClient locationClient;private static OnLocationChangeListener mOnLocationChangeListener;private static MyLocationListener mListener;public static void register(Context context, @Nullable OnLocationChangeListener onLocationChangeListener) {mOnLocationChangeListener = onLocationChangeListener;initLocation(context);}private static void initLocation(Context context) {locationClient = new AMapLocationClient(context);AMapLocation lastKnownLocation = locationClient.getLastKnownLocation();if (lastKnownLocation != null && mOnLocationChangeListener != null) {mOnLocationChangeListener.onLastKnownLocation(lastKnownLocation);}// 设置定位监听mListener = new MyLocationListener();locationClient.setLocationListener(mListener);}public static void startLocation() {locationClient.stopLocation();locationClient.setLocationOption(getDefaultOption(false));locationClient.startLocation();}public static void startOnceLocation() {locationClient.stopLocation();locationClient.setLocationOption(getDefaultOption(true));locationClient.startLocation();}public static void stopLocation() {locationClient.stopLocation();}public static void unregister() {stopLocation();locationClient.onDestroy();locationClient = null;mOnLocationChangeListener = null;mListener = null;}public static AMapLocationClientOption getDefaultOption(boolean isOnce) {AMapLocationClientOption mOption = new AMapLocationClientOption();mOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);//可选,设置定位模式,可选的模式有高精度、仅设备、仅网络。默认为高精度模式
//        mOption.setGpsFirst(false);//可选,设置是否gps优先,只在高精度模式下有效。默认关闭
//        mOption.setHttpTimeOut(30000);//可选,设置网络请求超时时间。默认为30秒。在仅设备模式下无效
//        mOption.setNeedAddress(true);//可选,设置是否返回逆地理地址信息。默认是trueif (isOnce) {mOption.setOnceLocation(true);//可选,设置是否单次定位。默认是falsemOption.setOnceLocationLatest(true);//可选,设置是否等待wifi刷新,默认为false.如果设置为true,会自动变为单次定位,持续定位时不要使用} else {mOption.setOnceLocation(false);mOption.setInterval(2_000);//可选,设置定位间隔。默认为2秒}mOption.setMockEnable(false); //设置是否允许模拟位置
//        AMapLocationClientOption.setLocationProtocol(AMapLocationClientOption.AMapLocationProtocol.HTTP);//可选, 设置网络请求的协议。可选HTTP或者HTTPS。默认为HTTP
//        mOption.setSensorEnable(false);//可选,设置是否使用传感器。默认是falsemOption.setWifiScan(true); //可选,设置是否开启wifi扫描。默认为true,如果设置为false会同时停止主动刷新,停止以后完全依赖于系统刷新,定位位置可能存在误差mOption.setLocationCacheEnable(true); //可选,设置是否使用缓存定位,默认为true
//        mOption.setGeoLanguage(AMapLocationClientOption.GeoLanguage.DEFAULT);//可选,设置逆地理信息的语言,默认值为默认语言(根据所在地区选择语言)return mOption;}public static class MyLocationListener implements AMapLocationListener {@Overridepublic void onLocationChanged(AMapLocation aMapLocation) {if (mOnLocationChangeListener != null) {mOnLocationChangeListener.onLocationChanged(aMapLocation);}}}public interface OnLocationChangeListener {void onLastKnownLocation(AMapLocation location);void onLocationChanged(AMapLocation location);}
}
public class GDLocationService extends Service {private volatile boolean isOnce = false;public static void actionStart(Context context) {actionStart(context, null);}public static void actionStart(Context context, String command) {context.startService(new Intent(context, GDLocationService.class).putExtra("command", command));}public static void actionStop(Context context) {context.stopService(new Intent(context, GDLocationService.class));}@Overridepublic void onCreate() {super.onCreate();GDLocationHelper.register(getApplicationContext(), new GDLocationHelper.OnLocationChangeListener() {@Overridepublic void onLastKnownLocation(AMapLocation location) {if (location != null) {Log.e("TAG", "onLastKnownLocation= " + location.toString());}}@Overridepublic void onLocationChanged(AMapLocation location) {if (location != null) {Log.e("TAG", "onLocationChanged= " + location.toString());if (isOnce) {stopSelf();}}}});}@Overridepublic int onStartCommand(Intent intent, int flags, int startId) {String command = intent.getStringExtra("command");switch (command) {case "once":isOnce = true;GDLocationHelper.startOnceLocation();break;case "stop":GDLocationHelper.stopLocation();break;case "start":default:isOnce = false;GDLocationHelper.startLocation();break;}return super.onStartCommand(intent, flags, startId);}@Nullable@Overridepublic IBinder onBind(Intent intent) {return null;}@Overridepublic void onDestroy() {super.onDestroy();GDLocationHelper.unregister();Log.e("TAG", "onDestroy");}
}

使用

// 开始定位   
GDLocationService.actionStart(MainActivity.this, "start");// 停止定位
GDLocationService.actionStart(MainActivity.this, "stop");// 单次定位
GDLocationService.actionStart(MainActivity.this, "once");
http://www.yayakq.cn/news/255082/

相关文章:

  • 如果做局域网影音网站wordpress 后台500
  • 一个专门做特卖的网站台州网站建设蓝渊
  • wordpress做下载型网站6网站开发 无形资产
  • 做欧美网站西安优秀的集团门户网站建设
  • 建立网站成本qq钓鱼网站
  • 智能科技网站模板wordpress模板+免费
  • 网站编辑知识服装设计公司室内平面图
  • 无锡专业网站制作asp网站500错误iis7
  • 建站宝盒模板引流黑科技app
  • 假冒建设银行网站如何做淘宝商城网站设计
  • 福州开发网站公司wordpress 完全静态化
  • 企业电子商务网站的域名命名凡科网产品矩阵
  • 亳州公司做网站seo优化方案ppt
  • 网站用户界面设计网络推广的渠道有哪些
  • 做电影网站犯罪吗软件系统开发全网优惠
  • 兴义网站建设公司企业网站设计需求文档
  • 龙岗网站价格如何查询网站备案进度查询
  • 网站建设方式有哪些网站域名如何申请
  • 浏阳做网站推荐文登市住房和城乡建设局网站
  • 万网x3主机l系统放两个网站做首饰网站
  • 简述企业建设网站的必要性网站建设模板ppt
  • 网站建设和app开发成都网站建设网络
  • 人力资源网站怎么做山东知名网络传媒有限公司
  • 河北省建设机械协会网站首页wordpress大菜单
  • 做三盛石材网站的公司专门做2手手机的网站
  • wordpress链接乱码兰州关键词优化效果
  • 邯郸网站建设哪家好档案网站开发
  • 东莞网站建设方案报价如何建设一个双语的网站
  • 广州哪个大学做网站制作好些的百度小程序优化
  • 未来做哪些网站能致富方案解决网站