Android三種GSM手機技術(shù)分析
更新時間:2012年12月05日 15:05:01 投稿:whsnow
本文將詳細介紹Android三種GSM技術(shù)比較差別,有感興趣的朋友可以參考下
復(fù)制代碼 代碼如下:
// 聲明LocationManager對象
LocationManager loctionManager;
// 通過系統(tǒng)服務(wù),取得LocationManager對象
loctionManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
方式一:
復(fù)制代碼 代碼如下:
// 通過GPS位置提供器獲得位置
String providerGPS = LocationManager.GPS_PROVIDER;
Location location = loctionManager.getLastKnownLocation(providerGPS);
方式二:
復(fù)制代碼 代碼如下:
// 通過基站位置提供器獲得位置
String providerNetwork = LocationManager.NETWORK_PROVIDER;
Location location = loctionManager.getLastKnownLocation(providerNetwork);
方式三:
復(fù)制代碼 代碼如下:
// 使用標準集合,讓系統(tǒng)自動選擇可用的最佳位置提供器,提供位置
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);
處理:
復(fù)制代碼 代碼如下:
// 顯示在EditText中
updateWithNewLocation(location);
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) {
}
// 當位置變化時觸發(fā)
@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("");
}
}
相關(guān)文章
android dialog背景模糊化效果實現(xiàn)方法
這篇文章主要為大家詳細介紹了android dialog背景模糊化效果的實現(xiàn)方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-04-04
Android開發(fā)使用strings.xml多語言翻譯解決方案
這篇文章主要為大家介紹了Android開發(fā)使用strings.xml多語言翻譯解決方案,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-06-06
Android使用Matrix旋轉(zhuǎn)圖片模擬碟片加載過程
這篇文章主要為大家詳細介紹了Android使用Matrix旋轉(zhuǎn)圖片模擬碟片加載過程,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-03-03
ProtoBuf動態(tài)拆分Gradle?Module解析
這篇文章主要為大家介紹了ProtoBuf動態(tài)拆分Gradle?Module解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-02-02

