Android三種GSM手機(jī)技術(shù)分析
更新時(shí)間:2012年12月05日 15:05:01 投稿:whsnow
本文將詳細(xì)介紹Android三種GSM技術(shù)比較差別,有感興趣的朋友可以參考下
復(fù)制代碼 代碼如下:
// 聲明LocationManager對(duì)象
LocationManager loctionManager;
// 通過系統(tǒng)服務(wù),取得LocationManager對(duì)象
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ù)制代碼 代碼如下:
// 使用標(biāo)準(zhǔn)集合,讓系統(tǒng)自動(dòng)選擇可用的最佳位置提供器,提供位置
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);// 高精度
criteria.setAltitudeRequired(false);// 不要求海拔
criteria.setBearingRequired(false);// 不要求方位
criteria.setCostAllowed(true);// 允許有花費(fèi)
criteria.setPowerRequirement(Criteria.POWER_LOW);// 低功耗
// 從可用的位置提供器中,匹配以上標(biāo)準(zhǔn)的最佳提供器
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) {
}
// 當(dāng)位置變化時(shí)觸發(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實(shí)現(xiàn)手勢(shì)劃定區(qū)域裁剪圖片
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)手勢(shì)劃定區(qū)域裁剪圖片,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05
Android實(shí)現(xiàn)多線程斷點(diǎn)續(xù)傳
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)多線程斷點(diǎn)續(xù)傳,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-07-07
Android自定義View實(shí)現(xiàn)投票進(jìn)度條
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)投票進(jìn)度條,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-11-11
基于Android studio3.6的JNI教程之ncnn人臉檢測(cè)mtcnn功能
這篇文章主要介紹了基于Android studio3.6的JNI教程之ncnn之人臉檢測(cè)mtcnn功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03
TabLayout實(shí)現(xiàn)ViewPager指示器的方法
這篇文章主要為大家詳細(xì)介紹了TabLayout實(shí)現(xiàn)ViewPager指示器,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-06-06
Android ViewPager實(shí)現(xiàn)智能無限循環(huán)滾動(dòng)回繞效果
這篇文章主要為大家詳細(xì)介紹了Android ViewPager實(shí)現(xiàn)智能無限循環(huán)滾動(dòng)回繞效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07

