GPSd定位
来源:互联网 发布:大学送礼给老师知乎 编辑:程序博客网 时间:2024/06/04 16:15
public class MainActivity extends AppCompatActivity { private TextView textView1; private LocationManager manager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); } private void initView() { textView1 = (TextView) findViewById(R.id.textView1); manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivityForResult(intent, 1); return; } String best = manager.getBestProvider(gettcriteria(), true); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. return; } manager.addGpsStatusListener(gps); manager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 1, locationListener); } LocationListener locationListener = new LocationListener() { @Override public void onLocationChanged(Location location) { up(location);// textView1.setText("经度---" + String.valueOf(location.getLongitude()) + "\n" + "纬度---" + String.valueOf(location.getLatitude()) + "\n海拔---" + String.valueOf(location.getAltitude())); } @Override public void onStatusChanged(String s, int i, Bundle bundle) { } @Override public void onProviderEnabled(String s) { } @Override public void onProviderDisabled(String s) { } }; //状态监听 GpsStatus.Listener gps = new GpsStatus.Listener() { @Override public void onGpsStatusChanged(int i) { } }; public Criteria gettcriteria() { Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); return criteria; } public void up(Location location) { textView1.setText("经度---" + String.valueOf(location.getLongitude()) + "\n" + "纬度---" + String.valueOf(location.getLatitude()) + "\n海拔---" + String.valueOf(location.getAltitude())); }}
阅读全文
0 0
- GPSd定位
- Installing GPSD
- GPSD测试
- GPS侦听器gpsd
- GPSD Time Service HOWTO
- FW: 开源的GPSD介绍
- gpsd build build from source (CentOS 6.5)
- 定位
- 定位
- 定位
- 定位
- 定位
- 定位
- 定位
- 定位
- 定位
- 定位
- 定位
- 继承和多态
- JDBC封装工具类
- Android Camera2.0 结合ImageReader拍照并解决图片偏转问题
- Spring @Value注入属性获取不到值
- 文件的上传(upload)和下载(download)(应用)
- GPSd定位
- Dynamic CRM 2016 IFD配置(6)Claims-based认证-外部访问配置
- spark on hive 写入hdfs 用csv格式
- c语言——表达式的计算
- java常用类库---大数操作(BigInteger,BigDecimal)
- 树莓派简介
- FMDB使用说明介绍
- MyBatis(一)
- TensorFlow实战Google深度学习框架第三章总结