/**** * 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 updates(定义一个更新位置监听)locationListener = 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. Android中自定义Dialog
  2. Android 自定义dialog 设置宽度
  3. Android圆形图片--自定义控件
  4. Android TabSwitcher自定义控件
  5. Android PopupWindow显示位置和显示大小
  6. android根据应用方向自动旋转的自定义view
  7. Android 自定义控件 按钮滚动选择
  8. android自定义带图片的title
  9. as gradle debug\values\generated.xml: Error: Duplicate res

随机推荐

  1. android企业实战视频培训班
  2. android官网没法访问issue
  3. android 浏览器问题
  4. android 安卓 开发 图片库获得图片的绝对
  5. Android Studio Emulator: Process finis
  6. 黑客黑科技?Python代码让android手机实现
  7. android运行模拟器脚本(批处理)
  8. 在Eclipse中进行Android单元测试
  9. android电池信息简介
  10. Android开发之拖动条/滑动条控件、星级评