Android-获取GPS数据方法

本文介绍了在Android中如何利用API获取GPS数据,包括经纬度、速度和高度等信息。通过LocationManager类获取位置提供商,并设置LocationListener进行位置更新监听。
摘要由CSDN通过智能技术生成

Android API中提供了获取位置信息的方法,可以获取GPS的经纬度,速度,高度等。

首先通过LocationManager类来获取设备有哪些相关的位置提供商。

下面为获取位置提供商的代码:

locationManager = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);
List<String> providers = locationManager.getAllProviders();
ListAdapter listAdapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, providers);
listview.setAdapter(listAdapter);
常见的位置提供商一般是GPS或passive

下面以GPS为例,获取位置信息,如经纬度,速度,高度等。

locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
updatelocation(location);//更新位置信息的方法
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000,0, new LocationListener());
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值