Ejemplo n.º 1
0
    /** Registers this object with the location service. */
    private void registerForLocationUpdates(boolean enableHighAccuracy) {
      ensureLocationManagerCreated();
      if (usePassiveOneShotLocation()) return;

      assert !mIsRunning;
      mIsRunning = true;

      // We're running on the main thread. The C++ side is responsible to
      // bounce notifications to the Geolocation thread as they arrive in the mainLooper.
      try {
        Criteria criteria = new Criteria();
        if (enableHighAccuracy) criteria.setAccuracy(Criteria.ACCURACY_FINE);
        mLocationManager.requestLocationUpdates(
            0, 0, criteria, this, ThreadUtils.getUiThreadLooper());
      } catch (SecurityException e) {
        Log.e(
            TAG,
            "Caught security exception while registering for location updates "
                + "from the system. The application does not have sufficient geolocation "
                + "permissions.");
        unregisterFromLocationUpdates();
        // Propagate an error to JavaScript, this can happen in case of WebView
        // when the embedding app does not have sufficient permissions.
        LocationProviderAdapter.newErrorAvailable(
            "application does not have sufficient " + "geolocation permissions.");
      } catch (IllegalArgumentException e) {
        Log.e(TAG, "Caught IllegalArgumentException registering for location updates.");
        unregisterFromLocationUpdates();
        assert false;
      }
    }
Ejemplo n.º 2
0
 private void updateNewLocation(Location location) {
   LocationProviderAdapter.newLocationAvailable(
       location.getLatitude(),
       location.getLongitude(),
       location.getTime() / 1000.0,
       location.hasAltitude(),
       location.getAltitude(),
       location.hasAccuracy(),
       location.getAccuracy(),
       location.hasBearing(),
       location.getBearing(),
       location.hasSpeed(),
       location.getSpeed());
 }