书上还有网上,在谷歌官方的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的都获取不到!求助啊,求助啊
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 10, listener);//移动超过10米且间隔大于1秒,才会发送消息,速度每秒5米,2秒一次,每秒>10米,1秒一次,所以,如果你的手机,从来没有用过GPS定上位置,也就是根本没有lastknown
然后你又不移动,所以,什么都没发生
2、保证你在XML中配置了相应的权限;
3、别在室内玩,因为室内一般是没有GPS信号的;
一般也就是这三种了。。Good