android通過gps獲取定位的位置數(shù)據(jù)和gps經(jīng)緯度
package com.action.android_test;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity {
private Location location=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//獲得位置服務(wù)的名稱
String serviceName = this.LOCATION_SERVICE;
//獲得位置服務(wù)的管理對象
LocationManager locationManager = (LocationManager)getSystemService(serviceName);
// 通過GPS獲取定位的位置數(shù)據(jù)
location = locationManager.getLastKnownLocation(locationManager.GPS_PROVIDER);
updateToNewLocation(location);
/**服務(wù)管理對象的監(jiān)聽器*/
//參數(shù)1:定位的方式 參數(shù)2:監(jiān)聽更新間隔時(shí)間(ms) 參數(shù)3:監(jiān)聽更新的距離(m) 參數(shù)4:監(jiān)聽的方法
locationManager.requestLocationUpdates(locationManager.GPS_PROVIDER, 2000, 10, new LocationListener() {
public void onStatusChanged(String provider, int status, Bundle extras) {
}
public void onProviderEnabled(String provider) {
}
public void onProviderDisabled(String provider) {
}
public void onLocationChanged(Location location) {
updateToNewLocation(location);
}
});
}
private void updateToNewLocation(Location location) {
TextView tv1;
tv1 = (TextView) this.findViewById(R.id.tv1);
if (location != null) {
double latitude = location.getLatitude();
double longitude= location.getLongitude();
tv1.setText("經(jīng)緯度為:n"+"維度:" + latitude+ "n經(jīng)度" + longitude);
} else {
tv1.setText("無法獲取地理信息");
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
- Android通過原生方式獲取經(jīng)緯度與城市信息的方法
- Android GPS獲取當(dāng)前經(jīng)緯度坐標(biāo)
- Android通過原生APi獲取所在位置的經(jīng)緯度
- Android編程實(shí)現(xiàn)根據(jù)經(jīng)緯度查詢地址并對獲取的json數(shù)據(jù)進(jìn)行解析的方法
- Android獲取當(dāng)前位置的經(jīng)緯度數(shù)據(jù)
- Android獲取經(jīng)緯度計(jì)算距離介紹
- Android 通過當(dāng)前經(jīng)緯度獲得城市的實(shí)例代碼
- android手機(jī)獲取gps和基站的經(jīng)緯度地址實(shí)現(xiàn)代碼
- Android獲取經(jīng)緯度的完美解決方案
相關(guān)文章
TabLayout實(shí)現(xiàn)ViewPager指示器的方法
這篇文章主要為大家詳細(xì)介紹了TabLayout實(shí)現(xiàn)ViewPager指示器,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-06-06
Android 8.0系統(tǒng)中應(yīng)用圖標(biāo)的適配技巧
今天小編就為大家分享一篇關(guān)于Android 8.0系統(tǒng)中應(yīng)用圖標(biāo)的適配技巧,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2018-10-10
使用User Agent分辨出Android設(shè)備類型的安全做法
這篇文章主要介紹了使用User Agent分辨出Android設(shè)備類型的安全做法,本文得出的結(jié)論是當(dāng)你依據(jù)檢測UA來判斷Android手機(jī)設(shè)備,請同時(shí)檢查android和mobile兩個(gè)字符串,需要的朋友可以參考下2015-01-01
Android使用KeyStore對數(shù)據(jù)進(jìn)行加密的示例代碼
這篇文章主要介紹了Android使用KeyStore對數(shù)據(jù)進(jìn)行加密的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-01-01
Android學(xué)習(xí)小結(jié)之獲取被啟動的Activity傳回的數(shù)據(jù)
這篇文章主要介紹了獲取被啟動的Activity傳回的數(shù)據(jù),非常不錯(cuò),介紹的非常詳細(xì),需要的朋友可以參考下2016-08-08

