您的位置:首页 > 工业机械 > 纺织机械 > [转载]GPS开发常用方法 和用Criteria确定android loca

[转载]GPS开发常用方法 和用Criteria确定android loca

luyued 发布于 2011-05-29 18:37   浏览 N 次  
原文地址:GPS开发常用方法 和用Criteria确定android location providerGPS开发常用方法(转载)作者:阿锋From:http://qq361119908.javaeye.com/blog/665074GPS常用方法总结

取得LocationProvider
Java代码
  1. public void getLocationProvider()
  2. {
  3. try
  4. {
  5. Criteria mCriteria01 = new Criteria();
  6. mCriteria01.setAccuracy(Criteria.ACCURACY_FINE);
  7. mCriteria01.setAltitudeRequired(false);
  8. mCriteria01.setBearingRequired(false);
  9. mCriteria01.setCostAllowed(true);
  10. mCriteria01.setPowerRequirement(Criteria.POWER_LOW);
  11. strLocationProvider =
  12. mLocationManager01.getBestProvider(mCriteria01, true);
  13. mLocation01 = mLocationManager01.getLastKnownLocation
  14. (strLocationProvider);
  15. }
  16. catch(Exception e)
  17. {
  18. mTextView01.setText(e.toString());
  19. e.printStackTrace();
  20. }
  21. }

获取经纬度,并返回GeoPoint对象
Java代码
  1. private GeoPoint getGeoByLocation(Location location)
  2. {
  3. GeoPoint gp = null;
  4. try
  5. {
  6. if (location != null)
  7. {
  8. double geoLatitude = location.getLatitude()*1E6;
  9. double geoLongitude = location.getLongitude()*1E6;
  10. gp = new GeoPoint((int) geoLatitude, (int) geoLongitude);
  11. }
  12. }
  13. catch(Exception e)
图文资讯
广告赞助商