书上还有网上,在谷歌官方的api文档的代码都尝试了还是无法获得 LocationManager locManager=(LocationManager)getSystemService(Context.LocationService);
Criteria criteria=new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setPowerRequirement(Criteria.POWER_LOW);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(false);//不需要花钱
String provider=locManager.getBestProvider(criteria, true);//addGpsStatusListener(listener);
Location location=locManager.getLastKnownLocation(provider);
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 10, listener);
这个方法无法获取到,后面的locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 10, listener);这个请求更新,根本就没有调用listener里面的代码LocationManager locationManager = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
// Define a listener that responds to locationupdates
LocationProvider provider=locationManager.getProvider(LocationManager.NETWORK_PROVIDER);
LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { // Called when a new location is found by the network
makeUseOfNewLocation(location); } public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} };
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
谷歌的这个也没法获取到,不过去奇怪的是我的1.6的手机可以获取位置,但是2.1的都获取不到!求助啊,求助啊
Criteria criteria=new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setPowerRequirement(Criteria.POWER_LOW);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(false);//不需要花钱
String provider=locManager.getBestProvider(criteria, true);//addGpsStatusListener(listener);
Location location=locManager.getLastKnownLocation(provider);
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 10, listener);
这个方法无法获取到,后面的locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 10, listener);这个请求更新,根本就没有调用listener里面的代码LocationManager locationManager = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
// Define a listener that responds to locationupdates
LocationProvider provider=locationManager.getProvider(LocationManager.NETWORK_PROVIDER);
LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { // Called when a new location is found by the network
makeUseOfNewLocation(location); } public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) {} public void onProviderDisabled(String provider) {} };
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
谷歌的这个也没法获取到,不过去奇怪的是我的1.6的手机可以获取位置,但是2.1的都获取不到!求助啊,求助啊
解决方案 »
- 求助关于android
- 求android openGL书籍
- android make 错误
- ListView 搭配 CheckBox 全选超过一屏幕数据后出错
- juv-rtmp-client 如何去远程服务器的视频在android控件上面播放
- 如何让图片的背景透明?
- 新手求助,NDK项目,运行不起来
- 刚刚接触Android,创建了一个project直接运行报错,求指导!多谢!
- android listview+button button点击事件失效 .在线等,马上结贴!
- 百度云推送在android机子上表现很差
- 这个问题真是难缠啊,ViewPager中的gridview无法获得OnItemLongClickListener.....
- 4.0以上版本如何获取添加APN权限
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 10, listener);//移动超过10米且间隔大于1秒,才会发送消息,速度每秒5米,2秒一次,每秒>10米,1秒一次,所以,如果你的手机,从来没有用过GPS定上位置,也就是根本没有lastknown
然后你又不移动,所以,什么都没发生
2、保证你在XML中配置了相应的权限;
3、别在室内玩,因为室内一般是没有GPS信号的;
一般也就是这三种了。。Good