mgr=(LocationManager)getSystemService(LOCATION_SERVICE);    mgr.addGpsStatusListener(listener);    Criteria criteria= new Criteria();    best=mgr.getBestProvider(criteria, true);    Location location= mgr.getLastKnownLocation("gps");

以上代码创建了一个位置对象

if(location.hasAccuracy()) accuracy=location.getAccuracy();//获取精度    if(location.hasAltitude()) altitude=location.getAltitude();//高度    if(location.hasBearing()) bearing=location.getBearing();    if(location.hasSpeed()) speed=location.getSpeed();latitude=location.getLatitude();longtitude=location.getLongitude();    time=location.getTime();//此时time是一个long型代表从1970年01月01日00:00:00至GPS取得位置信息的时间的毫秒数。//要转换成日期字符串格式,使用以下代码: SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd/HH/mm/ss/"); Log.d(tag,  "bb*1000,,"+sdf.format(new Date(time*1000L ))+"BB");  //如果time代表的是秒数要乘1000Log.d(tag,  "bb no*1000,,"+sdf.format(new Date(time ))+"BB");  //如果time代表毫秒数就不用乘1000了
注意要在AndroidManifest.xml文件中加入权限。如下:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>


listener = new GpsStatus.Listener() {            public void onGpsStatusChanged(int event) {            gpsstatus=mgr.getGpsStatus(null);            switch(event)            {            case GpsStatus.GPS_EVENT_FIRST_FIX:gpsstatus.getTimeToFirstFix();              case GpsStatus.GPS_EVENT_SATELLITE_STATUS:                   //得到所有收到的卫星的信息,包括 卫星的高度角、方位角、信噪比、和伪随机号(及卫星编号)            Log.d(tag, "get 卫星信息");            Iterable<GpsSatellite> allSatellites;            allSatellites = gpsstatus.getSatellites();            Iterator it=allSatellites.iterator();            String msg="";            while(it.hasNext())            {            GpsSatellite oSat = (GpsSatellite) it.next() ;              msg="\n*************\nazimuth:"+oSat.getAzimuth();            msg+="\nprn:"+oSat.getPrn();            msg+="\nsnr:"+oSat.getSnr()+"\n********\n";            }            Log.i(tag,msg);            break;                       case GpsStatus.GPS_EVENT_STARTED:                   //Event sent when the GPS system has started.           break;                       case GpsStatus.GPS_EVENT_STOPPED:                  //Event sent when the GPS system has stopped.             break;                       default :            break;            }                            }     };
记得在eclipse中,使用ctrl+shift+o以导入需要的包。

更多相关文章

  1. php获取手机设备信息
  2. android 3G 手机信号 信息获取
  3. android 获取 apk mainfest.xml中的信息
  4. android打开系统设置或信息界面
  5. android studio logcat 打印不出信息
  6. JAVA使用AXMLPrinter获取APK中Androidmanifest.xml信息
  7. Android进阶2之检索Android的图片库并显示图片详细信息
  8. 在android 输出log 信息 用于调试
  9. android使用百度地图SDK获取定位信息

随机推荐

  1. android test 和 instrumentation
  2. android去掉EditView的默认焦点问题
  3. android键盘隐藏
  4. (黎活明老师讲学)Android学习(五)---Frame动
  5. Google Admob广告Android(安卓)、简单应
  6. Android各版本市占率:果冻豆Android4.1遥
  7. Android 8.0 状态栏信号显示、信号定制
  8. Android简明开发教程九:创建应用程序框架
  9. 国内最全的Android市场,最全Android软件商
  10. Android 免安装应用