Apollo Save Tool深度实战:PS4游戏存档管理终极解决方案
2026/7/11 0:24:37
[历史归档]本文原发布于 cstriker1407.info 个人博客,内容为历史存档,仅供参考。
发布时间:2013-11-05| 标题:android应用开发笔记:GPS相关设置和距离计算|分类:编程 / android |标签:android·gps·百度地图
在 Android GPS 应用开发中,常需要检测 GPS 是否开启、跳转到位置设置页面、以及计算两点间距离。以下为工具类备忘:
publicclassGPSUtils{publicstaticbooleanisGPSOpen(Contextcontext){LocationManagerlm=(LocationManager)context.getSystemService(Context.LOCATION_SERVICE);returnlm.isProviderEnabled(LocationManager.GPS_PROVIDER);}publicstaticbooleanisAGPSOpen(Contextcontext){LocationManagerlm=(LocationManager)context.getSystemService(Context.LOCATION_SERVICE);returnlm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);}publicstaticvoidopenLocationSettings(Contextcontext){Intentintent=newIntent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);context.startActivity(intent);}/** 使用系统 API 计算两点距离,返回米 */publicstaticfloatcalcDistance(doublestartLatitude,doublestartLongitude,doubleendLatitude,doubleendLongitude){float[]result=newfloat[]{-1f,0f,0f};Location.distanceBetween(startLatitude,startLongitude,endLatitude,endLongitude,result);returnresult[0];}/** 使用百度地图 API 计算两点距离,返回米 */publicstaticfloatcalcDistanceByBD(doublestartLatitude,doublestartLongitude,doubleendLatitude,doubleendLongitude){return(float)DistanceUtil.getDistance(newGeoPoint((int)(startLatitude*1e6),(int)(startLongitude*1e6)),newGeoPoint((int)(endLatitude*1e6),(int)(endLongitude*1e6)));}}