❶ 请教android中如何调用GPS数据
内置的GPS的信息?
android.location.GpsStatus;
android.location.Location;
android.location.LocationListener;
android.location.LocationManager;
注册GPS Listener,然后就可以取到了。
❷ android怎样获得gps信息
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
private void getLocation()
{
// 获取位置管理服务
LocationManager locationManager;
String serviceName = Context.LOCATION_SERVICE;
locationManager = (LocationManager) this.getSystemService(serviceName);
// 查找到服务信息
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE); // 高精度
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW); // 低功耗
String provider = locationManager.getBestProvider(criteria, true); // 获取GPS信息
Location location = locationManager.getLastKnownLocation(provider); // 通过GPS获取位置
updateToNewLocation(location);
// 设置监听器,自动更新的最小时间为间隔N秒(1秒为1*1000,这样写主要为了方便)或最小位移变化超过N米
locationManager.requestLocationUpdates(provider, 100 * 1000, 500,
locationListener); }
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("维度:" + latitude+ "\n经度" + longitude);
} else {
tv1.setText("无法获取地理信息");
}
}
网络地图API调用地址:http://api.map..com/geocoder?output=json&location=纬度,经度&key=APP_KEY
谷歌地图服务API调用地址:http://maps.google.com/maps/api/geocode/json?latlng= 纬度,经度 &language=zh-CN&sensor=true
可以设置返回数据格式,JSON或者XML。
❸ 如何用安卓手机读取蓝牙GPS模块或记录仪中的轨迹数据
androidMTK现在可以读取GPS模块数据为kml/gpx格式,然后也可以通过蓝牙在手机之间传递。
❹ 如何获取安卓手机里的GPS数据和传感器数据
网上有很多的demo 一搜一大把 多看看API 还是说下吧 GPS大概的数据获取有getAccuracy()、getAltitude()、getBearing()、getLatitude()、getLongitude()、getSpeed()等这么几个
❺ mqtt 怎么实现android以后台service的方式获取gps数据,并定时发送到服务器
1 从Service继承一个类。
2 创建startService()方法。
3 创建endService()方法 重载onCreate方法和onDestroy方法,并在这两个方法里面来调用startService以及endService。
4 在startService中,通过getSystemService方法获取Context.LOCATION_SERVICE。
5 基于LocationListener实现一个新类。默认将重载四个方法onLocationChanged、onProviderDisabled、onProviderEnabled、onStatusChanged。对于onLocationChanged方法是我们更新最新的GPS数据的方法。一般我们的操作都只需要在这里进行处理。
6 调用LocationManager的requestLocationUpdates方法,来定期触发获取GPS数据即可。在onLocationChanged函数里面可以实现我们对得到的经纬度的最终操作。
7 最后在我们的Activity里面通过按钮来启动Service,停止Service。
示意代码如下:
package com.offbye.gpsservice;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
public class GPSService extends Service {
// 2000ms
private static final long minTime = 2000;
// 最小变更距离10m
private static final float minDistance = 10;
String tag = this.toString();
private LocationManager locationManager;
private LocationListener locationListener;
private final IBinder mBinder = new GPSServiceBinder();
public void startService() {
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationListener = new GPSServiceListener();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTime, minDistance,
locationListener);
}
public void endService() {
if (locationManager != null && locationListener != null) {
locationManager.removeUpdates(locationListener);
}
}
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return mBinder;
}
❻ Android 怎样稳定的获取原生GPS数据
LocationManager类的对象获取由系统提供
为一个LocationManager对象建立一个对象引用
❼ android 如何去获取手机Gps的信号强度
首先,进入设置选项,在主屏界面中按下Android手机Menu键,在弹出的进阶菜单中选择最后一项“Settings”;
将滑动条拖动至最下方,点击“About Phone”分类;
选择第二项“Status”分类;
这时,就能够看到“Signal Strength”选项,前面的-xx(这是一个负数数字)dBm则是手机信号强度。一般“0”—“-50”之间都是一个非常不错的信号强度,而数值越小则代表着信号越差。
❽ Android 怎样稳定的获取原生GPS数据
定位了就有经纬度,没定位,则一直闪的;
一般是4个星的时候 会定位。
所以可以根据是否获取有效的经纬度信息来判断是否定位。
卫星的个数 sv_status也是可以通过API获取的。LOCATION类
给你一段我的代码,看看就知道了。
locationManager.addGpsStatusListener(statusListener);//侦听GPS状态
private GpsStatus.Listener statusListener = new GpsStatus.Listener()
{
public void onGpsStatusChanged(int event)
{
// TODO Auto-generated method stub
GpsStatus gpsStatus= locationManager.getGpsStatus(null);
Log.v(TAG,"GPS status listener ");
//Utils.DisplayToastShort(GPSService.this, "GPS status listener ");
switch(event)
{
case GpsStatus.GPS_EVENT_FIRST_FIX:{
//第一次定位时间UTC gps可用
//Log.v(TAG,"GPS is usable");
int i=gpsStatus.getTimeToFirstFix();
Utils.DisplayToastShort(GPSService.this, "GPS 第一次可用 "+i);
Utils.setGPSStatus(Utils.GPS_STATUS.START);
break;
}
case GpsStatus.GPS_EVENT_SATELLITE_STATUS:{//周期的报告卫星状态
//得到所有收到的卫星的信息,包括 卫星的高度角、方位角、信噪比、和伪随机号(及卫星编号)
Iterable<GpsSatellite> allSatellites;
allSatellites = gpsStatus.getSatellites();
Iterator<GpsSatellite>iterator = allSatellites.iterator();
int numOfSatellites = 0;
int maxSatellites=gpsStatus.getMaxSatellites();
while(iterator.hasNext() && numOfSatellites<maxSatellites){
numOfSatellites++;
iterator.next();
}
Log.v(TAG,"GPS is **unusable** "+ numOfSatellites +" "+ maxSatellites);
if( numOfSatellites < 3){
// Utils.DisplayToastShort(GPSService.this, "***卫星少于3颗***");
Utils.setGPSStatus(Utils.GPS_STATUS.STOP);
} else if(numOfSatellites > 7){
Utils.setGPSStatus(Utils.GPS_STATUS.START);
}
break;
}
case GpsStatus.GPS_EVENT_STARTED:{
//Utils.DisplayToastShort(GPSService.this, "GPS start Event");
break;
}
case GpsStatus.GPS_EVENT_STOPPED:{
//Utils.DisplayToastShort(GPSService.this, "GPS **stop*** Event");
Utils.setGPSStatus(Utils.GPS_STATUS.STOP);
break;
}
default :
break;
}
}
};