/**** * GPS Process *  * First of all call listener of Location * then checking for GPS_PROVIDER * if not available then check for NETWORK_PROVIDER * and if its also not available then pass 0.00,0.00 to longitude and latitude *    **** *//** PROCESS for Get Longitude and Latitude **/locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);// Define a listener that responds to location updateslocationListener = new LocationListener() {public void onLocationChanged(Location location) {// Called when a new location is found by the network location provider.longitude = String.valueOf(location.getLongitude());latitude = String.valueOf(location.getLatitude());Log.d(TAG, "changed Loc : " + longitude + ":" + latitude);}public void onStatusChanged(String provider, int status, Bundle extras) {}public void onProviderEnabled(String provider) {}public void onProviderDisabled(String provider) {}};// getting GPS statusisGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);// check if GPS enabledif (isGPSEnabled) {Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);if (location != null) {longitude = String.valueOf(location.getLongitude());latitude = String.valueOf(location.getLatitude());locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);} else {location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);if (location != null) {longitude = String.valueOf(location.getLongitude());latitude = String.valueOf(location.getLatitude());locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);} else {longitude = "0.00";latitude = "0.00";}}}// see http://androidsnippets.com/android-gps-location-with-listener



更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. 备忘的小知识
  2. Android中使用DownloadManager下载并安装
  3. EventThread线程对VSync的接收
  4. 在Android中借助TensorFlow使用机器学习(
  5. Tensorflow编译android平台的so库和jar包
  6. Android(安卓)studio JavaDoc的使用
  7. Android——systrace使用分析
  8. android,actionbar,menu显示,图片,菜单禁
  9. React Native Android(安卓)即时热更新bu
  10. Android对ListView控件增删改查