国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android三種GSM手機定位技術分析

2020-04-11 12:39:36
字體:
來源:轉載
供稿:網友
復制代碼 代碼如下:

// 聲明LocationManager對象
LocationManager loctionManager;
// 通過系統服務,取得LocationManager對象
loctionManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

方式一:
復制代碼 代碼如下:

// 通過GPS位置提供器獲得位置
String providerGPS = LocationManager.GPS_PROVIDER;
Location location = loctionManager.getLastKnownLocation(providerGPS);

方式二:
復制代碼 代碼如下:

// 通過基站位置提供器獲得位置
String providerNetwork = LocationManager.NETWORK_PROVIDER;
Location location = loctionManager.getLastKnownLocation(providerNetwork);

方式三:
復制代碼 代碼如下:

// 使用標準集合,讓系統自動選擇可用的最佳位置提供器,提供位置
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);// 高精度
criteria.setAltitudeRequired(false);// 不要求海拔
criteria.setBearingRequired(false);// 不要求方位
criteria.setCostAllowed(true);// 允許有花費
criteria.setPowerRequirement(Criteria.POWER_LOW);// 低功耗
// 從可用的位置提供器中,匹配以上標準的最佳提供器
String provider = loctionManager.getBestProvider(criteria, true);
// 獲得最后一次變化的位置
Location location = loctionManager.getLastKnownLocation(provider);


處理:
復制代碼 代碼如下:

// 顯示在EditText中
updateWithNewLocation(location);
// 監聽位置變化,2秒一次,距離10米以上
loctionManager.requestLocationUpdates(provider, 1000, 1, locationListener);

監聽器及顯示:
復制代碼 代碼如下:

// 位置監聽器
private final LocationListener locationListener = new LocationListener() {
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
// 當位置變化時觸發
@Override
public void onLocationChanged(Location location) {
// 使用新的location更新TextView顯示
updateWithNewLocation(location);
}
};
private void updateWithNewLocation(Location location) {
if (location != null) {
double lat = location.getLatitude();
double lng = location.getLongitude();
latStr = format.format(lat);
lonStr = format.format(lng);
txtLat.setText(latStr);
txtLon.setText(lonStr);
} else {
txtLat.setText("");
txtLon.setText("");
}
}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 深圳市| 都安| 横山县| 滕州市| 沂南县| 通江县| 司法| 普安县| 桃江县| 新余市| 个旧市| 平罗县| 宁国市| 特克斯县| 乌鲁木齐县| 黄山市| 慈溪市| 湖北省| 利川市| 新昌县| 涞水县| 筠连县| 芜湖县| 凭祥市| 东丰县| 千阳县| 遂溪县| 拉萨市| 子洲县| 车致| 三都| 芷江| 永登县| 申扎县| 绍兴市| 山西省| 汕头市| 雅安市| 广汉市| 丰镇市| 克山县|