Android 打开 GPS 导航并获取位置信息
2010-10-19 17:18:28 来源:WEB开发网核心提示:29 String serviceName = Context.LOCATION_SERVICE;30 locationManager = (LocationManager) getSystemService(serviceName);31 locationManager.setTestProviderEnabled(
29 String serviceName = Context.LOCATION_SERVICE;
30 locationManager = (LocationManager) getSystemService(serviceName);
31 locationManager.setTestProviderEnabled("gps", true);
32 provider = locationManager.getBestProvider(criteria, true);
33 Log.d("provider", provider);
34
35 llistener = new LocationListener() {
36 @Override
37 public void onLocationChanged(Location location)
38 {
39 // TODO Auto-generated method stub
40 Log.i("onLocationChanged", "come in");
41 if (location != null)
42 {
43 Log.w("Location", "Current altitude = "
44 + location.getAltitude());
45 Log.w("Location", "Current latitude = "
46 + location.getLatitude());
47 }
48 locationManager.removeUpdates(this);
49 locationManager.setTestProviderEnabled(provider, false);
50 }
51
52 @Override
53 public void onProviderDisabled(String provider)
54 {
30 locationManager = (LocationManager) getSystemService(serviceName);
31 locationManager.setTestProviderEnabled("gps", true);
32 provider = locationManager.getBestProvider(criteria, true);
33 Log.d("provider", provider);
34
35 llistener = new LocationListener() {
36 @Override
37 public void onLocationChanged(Location location)
38 {
39 // TODO Auto-generated method stub
40 Log.i("onLocationChanged", "come in");
41 if (location != null)
42 {
43 Log.w("Location", "Current altitude = "
44 + location.getAltitude());
45 Log.w("Location", "Current latitude = "
46 + location.getLatitude());
47 }
48 locationManager.removeUpdates(this);
49 locationManager.setTestProviderEnabled(provider, false);
50 }
51
52 @Override
53 public void onProviderDisabled(String provider)
54 {
更多精彩
赞助商链接