在Android的GPS开发中,使用location的想光API无法获取用户location,代码如下
locationMgr = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
        locationMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, mLocationListener);
        Location     lastKnownLocation = locationMgr.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        double latitude = lastKnownLocation.getLatitude();     //经度   
        double longitude = lastKnownLocation.getLongitude(); //纬度   
        double altitude =  lastKnownLocation.getAltitude();  
        locationMgr.removeUpdates(mLocationListener);
lastKnownLocation 为空AndroidManifest.xml中
 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>  
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>  
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>  
    <uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES"/>请教

解决方案 »

  1.   

    是在模拟器上还是在设备上?设备要到室外才能收到GPS信号的.
      

  2.   

    模拟器 emultor control 传经纬度
    移动设备 室外
      

  3.   

    provide为GPS时,要靠卫星定位的,需要将手机移到室外
    另外lastKnownLocation 是有可能为空的所以要使用另一种方式
    locationMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, mLocationListener);
    设置监听器的方式,但是设置了监听器,也就是mLocationListener应该会有那三个方法吧,你应该重写了吧
    当location变化时,就可以打印location了,一般过程较长,最好是在室外测试,或把手伸到窗外另外:locationMgr.removeUpdates(mLocationListener);这句这么早调用了,,,还监听什么嘛
      

  4.   

    所以Google Map的定位在室内用的并不是GPS了
      

  5.   

    已经解决了,
    如果有Wifi的环境下可以使用NETWORK__PROVIDER
    户外的话使用GPS_PROVIDERcallback第一次大概会有等待一段时间才会有反映,试验机器是HTC Incridble S
      

  6.   

    GPS不是一次就能取到经纬度的,当它取不到时它会一直在那取直到取到为止,最好是添加上网络定位、基站定位
      

  7.   

    楼主你好,我也在学习gps定位的做法,能不能分享一下你的定位部分的代码?[email protected],非常感谢