GPS功能实现--OS4.5(模拟器能得到坐标,真机得不到)
LocationListenerImpl locationListener; LocationProvider provider; Criteria criteria = new Criteria(); criteria.setHorizontalAccuracy(criteria.NO_REQUIREMENT); criteria.setVerticalAccuracy(criteria.NO_REQUIREMENT); criteria.setPreferredPowerConsumption(criteria.POWER_USAGE_MEDIUM); criteria.setCostAllowed(false); try { provider = LocationProvider.getInstance(criteria); provider.setLocationListener(locationListener, 1, 1, 1); } catch (Exception e) { e.printStackTrace(); }
import javax.microedition.location.Location; import javax.microedition.location.LocationListener; import javax.microedition.location.LocationProvider; public class LocationListenerImpl implements LocationListener { public void locationUpdated(LocationProvider arg0, Location arg1) { String latitude = arg1.getQualifiedCoordinates().getLatitude()+""; String longitude = arg1.getQualifiedCoordinates().getLongitude()+""; //这个坐标在真机上就是得不到... } } public void providerStateChanged(LocationProvider arg0, int arg1) { // TODO Auto-generated method stub }}