android GPS定位代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
public class MainActivity extends Activity {
     
    private LocationManager lm;
     
    private MyLocationListener listener;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        lm = (LocationManager) getSystemService(LOCATION_SERVICE);
        listener = new MyLocationListener();
        lm.requestLocationUpdates("gps", 0, 0, listener);
         
    }
     
    public class MyLocationListener implements LocationListener{
 
        //当位置发生变化的时候
        @Override
        public void onLocationChanged(Location location) {
            String  longitude = "经度:"+location.getLongitude()+"\n";
            String  latitude = "纬度:"+location.getLatitude()+"\n";
            String accuracy = "精确度:"+location.getAccuracy()+"\n";
             
            TextView textView = new TextView(MainActivity.this);
            textView.setText(longitude+latitude+accuracy);
            setContentView(textView);
             
        }
 
        //某个位置提供者的状态发生变化的时候 打开--》关闭 ;关闭--》开启
        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
              
        }
 
        //某个位置提供者可用
        @Override
        public void onProviderEnabled(String provider) {
             
        }
        //某个位置提供者不可用
 
        @Override
        public void onProviderDisabled(String provider) {
             
        }
         
         
    }
     
    @Override
    protected void onDestroy() {
        super.onDestroy();
        lm.removeUpdates(listener);
        listener = null;
         
    }
 
     
 
}
上一篇:上:Spark VS Flink – 下一代大数据计算引擎之争,谁主沉浮?


下一篇:linux gdb 调试SO库