【问题标题】:using location api in android [duplicate]在android中使用位置api [重复]
【发布时间】:2012-11-08 22:37:03
【问题描述】:

可能重复:
What is the simplest and most robust way to get the user’s current location in Android?

我研究了android的位置api并尝试了使用locationChanged方法的基本应用程序,并提供了一个最简单的解决方案来跟踪使用位置。

如何在同一上下文中跟踪用户的以下操作

  • 用户输入新位置
  • 用户离开当前位置

还有关于以下因素:

  • 新位置不在旧位置的 x 米范围内
  • 以及比较上一个位置和新位置所需的属性

【问题讨论】:

    标签: android geolocation maps location android-location


    【解决方案1】:

    这还不错。关于这件事的官方Android SDK其实还不错。 Official Google Documentation on it

    基本上,它使用的界面会在每种情况出现时运行功能。因此,只要位置根据触发该参数的任何参数发生更改,就会调用 onLocationChanged。另外,我建议只使用不同的提供商类型

    最难的部分是距离部分。有公式可以使用经度和纬度计算距离。

    来自文档:

    // Acquire a reference to the system Location Manager
    LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    
    // Define a listener that responds to location updates
    LocationListener locationListener = new LocationListener() {
        public void onLocationChanged(Location location) {
          // Called when a new location is found by the network location provider.
          makeUseOfNewLocation(location);
        }
    
        public void onStatusChanged(String provider, int status, Bundle extras) {}
    
        public void onProviderEnabled(String provider) {}
    
        public void onProviderDisabled(String provider) {}
      };
    
    // Register the listener with the Location Manager to receive location updates
    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-02
      • 1970-01-01
      • 1970-01-01
      • 2013-02-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多