Ejemplo n.º 1
0
  @Override
  public void onConnected(Bundle bundle) {
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
            != PackageManager.PERMISSION_GRANTED
        && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
            != PackageManager.PERMISSION_GRANTED) {
      // TODO: Consider calling
      //    ActivityCompat#requestPermissions
      // here to request the missing permissions, and then overriding
      //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
      //                                          int[] grantResults)
      // to handle the case where the user grants the permission. See the documentation
      // for ActivityCompat#requestPermissions for more details.
      return;
    }

    Location location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);

    if (location == null) {
      LocationServices.FusedLocationApi.requestLocationUpdates(
          mGoogleApiClient, mLocationRequest, this);
    } else {
      handleNewLocation(location);
    }

    Log.i(TAG, "Location services connected.");
  }
Ejemplo n.º 2
0
 @Override
 public void onConnected(Bundle bundle) {
   location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
   if (location == null) {
     LocationServices.FusedLocationApi.requestLocationUpdates(
         mGoogleApiClient, locationRequest, this);
   }
 }
Ejemplo n.º 3
0
  // request new location and update UI accordingly
  public void startLocationUpdates() {
    if (!mGoogleApiClient.isConnected()) mGoogleApiClient.connect();
    mLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
    LocationServices.FusedLocationApi.requestLocationUpdates(
        mGoogleApiClient, mLocationRequest, MainActivity.this);

    mPagerAdapter.getMainWeatherFragment().handleNewLocation(mLocation);
    Log.i(TAG, "Main Activity startLocationUpdates method is done.");
  }
 private void restartLocationUpdates() {
   mUpdateCount = 0;
   Location lastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
   if (lastLocation != null) {
     onLocationChanged(lastLocation, true);
   }
   LocationServices.FusedLocationApi.requestLocationUpdates(
       mGoogleApiClient, getLocationRequest(), this);
 }
Ejemplo n.º 5
0
 @Override
 public void onConnected(Bundle bundle) {
   // If current location is stale listen for location updates
   Location location = LocationServices.FusedLocationApi.getLastLocation(client);
   lastLocation = (location == null) ? lastLocation : location;
   if (lastLocation == null || isLoctionStale(lastLocation)) {
     LocationServices.FusedLocationApi.requestLocationUpdates(client, getRequest(), this);
   } else {
     getPosts();
   }
 }
 @Override
 public void onConnected(Bundle bundle) {
   Log.i(TAG, "Location services connected.");
   location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
   if (location == null) {
     LocationServices.FusedLocationApi.requestLocationUpdates(
         mGoogleApiClient, locationRequest, this);
   } else {
     handleNewLocation(location);
   }
 }
Ejemplo n.º 7
0
 @Override
 public void onConnected(Bundle bundle) {
   // request location updates
   LocationServices.FusedLocationApi.requestLocationUpdates(
       mGoogleApiClient, createLocationRequest(), this);
   Location loc = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
   if (accepted) {
     for (HelperOrPinLocationUpdate l : locationUpdates) l.onLocationUpdate(loc);
   }
   lastLocation = loc;
 }
Ejemplo n.º 8
0
 @Override
 public void onConnected(Bundle bundle) {
   L.m("onConnected");
   mLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
   if (mLocation == null) {
     LocationServices.FusedLocationApi.requestLocationUpdates(
         mGoogleApiClient, mLocationRequest, this);
   } else {
     L.s(this, mLocation.toString());
     updateLocation(mLocation);
   }
 }
 @Override
 public void onConnected(Bundle bundle) {
   // Register for location updates
   Location location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
   if (location == null) {
     if (PackageManager.PERMISSION_GRANTED
         == ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)) {
       // enable location updates
       LocationServices.FusedLocationApi.requestLocationUpdates(
           mGoogleApiClient, mLocationRequest, this);
     }
   } else {
     onLocationChanged(location);
   }
 }
Ejemplo n.º 10
0
  @Override
  public void onConnected(Bundle bundle) {
    Location location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);

    if (location == null) {
      LocationServices.FusedLocationApi.requestLocationUpdates(
          mGoogleApiClient, mLocationRequest, this);
    } else {
      handleNewLocation(location);
    }

    LocationServices.GeofencingApi.addGeofences(
            mGoogleApiClient, getGeofencingRequest(), getGeofencePendingIntent())
        .setResultCallback(this);
  }
Ejemplo n.º 11
0
 @Override
 public void onConnected(Bundle bundle) {
   mCurrentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
   Log.d(TAG, "Last location: " + mCurrentLocation);
   if (mCurrentLocation != null) {
     mLatitude = mCurrentLocation.getLatitude();
     mLongitude = mCurrentLocation.getLongitude();
     Geocoder gcd = new Geocoder(this, Locale.getDefault());
     List<Address> addresses = null;
     try {
       addresses = gcd.getFromLocation(mLatitude, mLongitude, 1);
     } catch (IOException e) {
       e.printStackTrace();
     }
     if (addresses != null && addresses.size() > 0) {
       mLocationName.setText(addresses.get(0).getLocality());
     }
   } else {
     // use hard-coded location as can't update to current
     // Toast.makeText(this, "Using default lat & long", Toast.LENGTH_LONG).show();
   }
   // getForecast(mLatitude, mLongitude);
   try {
     startLocationUpdates();
   } catch (Exception e) {
     Log.d(TAG, "Inside the catch block: " + e);
   }
 }
 protected void startLocationUpdates() {
   if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)
       == PackageManager.PERMISSION_GRANTED) {
     LocationServices.FusedLocationApi.requestLocationUpdates(
         googleApiClient, locationRequest, this);
   }
 }
  @Override
  public void onConnected(Bundle bundle) {
    Log.i(TAG, "Location services connected.");

    Location lastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);

    if (lastLocation == null) {
      Toast.makeText(
              FullScreenMapActivity.this, "There is currently no connectivity", Toast.LENGTH_LONG)
          .show();
    } else {

      ParseGeoPoint point =
          new ParseGeoPoint(lastLocation.getLatitude(), lastLocation.getLongitude());
      ParseUser currentUser = ParseUser.getCurrentUser();
      currentUser.put("location", point);
      currentUser.saveInBackground();

      mGoogleMap.animateCamera(CameraUpdateFactory.zoomIn());

      CameraPosition cameraPosition =
          new CameraPosition.Builder()
              .target(new LatLng(lastLocation.getLatitude(), lastLocation.getLongitude()))
              .zoom(12)
              .bearing(90)
              .tilt(30)
              .build();

      mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
    }
  }
Ejemplo n.º 14
0
  /** @brief This function starts the GPS */
  private void stopLocation() {
    // Check if we need to set up Google API
    if (sGPSIsOn) {
      if (sGoogleApi == null) {
        // Build API
        sGoogleApi =
            new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .build();

        // Thank the 6 God for blockingConnect
        ConnectionResult what = sGoogleApi.blockingConnect();
      }

      if (sLocationIntent == null) {
        Intent intent = new Intent(this, InnerLocationService.class);
        sLocationIntent =
            PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
      }
      if (!sQuickGPSIsOn) {
        InnerLocationService.sPreviousLocation = null;
        InnerLocationService.sCurrentLocation = null;
      }

      LocationServices.FusedLocationApi.removeLocationUpdates(sGoogleApi, sLocationIntent);
      sGPSIsOn = false;
      sQuickGPSIsOn = false;
    }
  }
 private void attachRecorder() {
   if (locationClientAPI == null) {
     connectToPlayAPI();
   } else if (locationClientAPI.isConnected()) {
     Integer priority = translateDesiredAccuracy(config.getDesiredAccuracy());
     LocationRequest locationRequest =
         LocationRequest.create()
             .setPriority(priority) // this.accuracy
             .setFastestInterval(config.getFastestInterval())
             .setInterval(config.getInterval());
     // .setSmallestDisplacement(config.getStationaryRadius());
     LocationServices.FusedLocationApi.requestLocationUpdates(
         locationClientAPI, locationRequest, this);
     Log.d(
         TAG,
         "- locationUpdateReceiver NOW RECORDING!!!!!!!!!! with priority: "
             + priority
             + ", fastestInterval: "
             + config.getFastestInterval()
             + ", interval: "
             + config.getInterval()
             + ", smallestDisplacement: "
             + config.getStationaryRadius());
   } else {
     locationClientAPI.connect();
   }
 }
 public void stopUpdates() {
   // revert previous location settings
   final ContentResolver contentResolver = getContentResolver();
   Settings.Secure.putInt(contentResolver, Settings.Secure.LOCATION_MODE, mCurrentLocationmode);
   LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
   stopSelf();
 }
Ejemplo n.º 17
0
  @Override
  public void onConnected(Bundle bundle) {
    Log.i(TAG, "onConnected");
    mCurrentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
    LatLng postion = new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude());
    mGoogleMap.setMyLocationEnabled(true);
    mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(postion, 3));
    mGoogleMap.setOnMarkerClickListener(this);

    for (int i = 0; i < mOficinasBeanList.size(); i++) {
      OficinasBean oficinasBean = mOficinasBeanList.get(i);
      String[] coordinates = oficinasBean.getCoordinates().split(",");
      if (coordinates.length == 2) {
        LatLng location =
            new LatLng(Double.parseDouble(coordinates[0]), Double.parseDouble(coordinates[1]));

        Marker marker =
            mGoogleMap.addMarker(
                new MarkerOptions()
                    .title(oficinasBean.getcOffice())
                    .snippet(Integer.toString(i))
                    .position(location));
      }
    }
  }
 /**
  * Called each time we receive a new location notification. - sends the location back to the
  * LocationReceiver that requested the location.
  */
 public void onLocationChanged(Location loc) {
   Log.i(TAG, "onLocationChanged() - location found.");
   if (loc != null) {
     Log.i(TAG, "OnLocationChanged() - returning Location (" + loc.toString() + ")");
     Toast.makeText(
         mContext,
         "Location is (" + loc.getLatitude() + "," + loc.getLongitude() + ")",
         Toast.LENGTH_LONG);
     LonLat ll;
     ll =
         new LonLat(
             loc.getLongitude(),
             loc.getLatitude(),
             loc.getAccuracy(),
             loc.getProvider(),
             new Date(loc.getTime()));
     // Now we have a location, unsubscribe from location updates.
     LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
     // And retrn the location to the requesting process.
     lr.onLocationFound(ll);
   } else {
     Log.i(TAG, "onLocationChanged() - Location is null????");
     Toast.makeText(mContext, "No Location Detected", Toast.LENGTH_LONG).show();
     lr.onLocationFound(null);
   }
 }
Ejemplo n.º 19
0
  /**
   * This is where google play services gets connected and we can now find recent location.
   *
   * <p>Note that all the complex stuff about connecting to Google Play Services (just to get
   * location) is from http://developer.android.com/training/location/retrieve-current.html and I
   * don't actually know how to test it.
   *
   * @param connectionHint
   */
  @Override
  public void onConnected(Bundle connectionHint) {
    Log.i(
        TAG,
        "Connected to Google Play services mLastCameraPosition==" + (mLastCameraPosition != null));

    mPlayServicesConnectionStatus = true;

    mLastDeviceLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);

    // If we are now connected, but still don't have a location, use a bogus default.
    if (mLastDeviceLocation == null) {
      mLastDeviceLocation = new Location("default");

      mLastDeviceLocation.setLatitude(
          Double.parseDouble(getResources().getString(R.string.map_default_latitude)));
      mLastDeviceLocation.setLongitude(
          Double.parseDouble(getResources().getString(R.string.map_default_longitude)));
    }

    // mMap may not yet be initialized in some cases; Connect happens before map setup.
    if (mMap != null) {
      mMap.setMyLocationEnabled(true);

      if (getSavedCameraPosition() == null) {
        setMapToCurrentLocation();
      }
    }
  }
 @Override
 public void onConnected(Bundle bundle) {
   if (wasLocalized) {
     return;
   }
   LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, REQUEST, this);
 }
Ejemplo n.º 21
0
 @Override
 public void onConnected(Bundle bundle) {
   mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
   if (mLastLocation != null) {
     // getting the latitude value
     double latitudeValue = mLastLocation.getLatitude();
     // getting the longitude value
     double longitudeValue = mLastLocation.getLongitude();
     if (checkServices()) {
       if (initMap()) {
         // update the map with the current location
         gotoLocation(latitudeValue, longitudeValue, 15);
         mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
         mMap.setOnMarkerClickListener(this);
         mMap.setOnMapClickListener(this);
         mMap.setOnMapLongClickListener(this);
         mMap.setOnInfoWindowClickListener(this);
         try {
           viewMarkers();
         } catch (JSONException e) {
           e.printStackTrace();
         }
       }
     }
   }
 }
Ejemplo n.º 22
0
 @Override
 public void onLocationChanged(Location location) {
   // Once location update is received remove listener and retrieve posts
   lastLocation = location;
   LocationServices.FusedLocationApi.removeLocationUpdates(client, this);
   getPosts();
 }
Ejemplo n.º 23
0
 @Override
 protected void onPause() {
   super.onPause();
   if (mGoogleApiClient.isConnected()) {
     LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
     mGoogleApiClient.disconnect();
   }
 }
  private void displayLocation() {

    mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);

    if (mLastLocation != null) {
      drawMarker(mLastLocation.getLatitude(), mLastLocation.getLongitude());
    }
  }
 @Override
 public void run() {
   lastLocation = LocationServices.FusedLocationApi.getLastLocation(apiClient);
   currLocation = LocationServices.FusedLocationApi.getLastLocation(apiClient);
   if (lastLocation != null) {
     currLocation.setLatitude(latIntrepid);
     currLocation.setLongitude(longIntrepid);
     locationDifference = lastLocation.distanceTo(currLocation);
     if (locationDifference < DISPLACEMENT) {
       Log.e("location", "im within radius");
       chechIn = true;
     } else {
       Log.e("location", "in else of display");
       Log.e("location", lastLocation.toString() + ",");
     }
   }
 }
 /** ************************** Google API connection ****************************************** */
 @Override
 public void onConnected(Bundle connectionHint) {
   lastKnownLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
   if (lastKnownLocation != null) {
     latitude = String.valueOf(lastKnownLocation.getLatitude());
     longitude = String.valueOf(lastKnownLocation.getLongitude());
   }
 }
 protected void startLocationUpdates() {
   mLocationRequest = new LocationRequest();
   mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
   mLocationRequest.setInterval(UPDATE_INTERVAL);
   mLocationRequest.setFastestInterval(FASTEST_INTERVAL);
   LocationServices.FusedLocationApi.requestLocationUpdates(
       mGoogleApiClient, mLocationRequest, this);
 }
Ejemplo n.º 28
0
  @Override
  public void onConnected(Bundle bundle) {
    Location location = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
    if (location == null) {
      try {
        LocationServices.FusedLocationApi.requestLocationUpdates(
            googleApiClient,
            locationRequest,
            (com.google.android.gms.location.LocationListener) this);
      } catch (ClassCastException e) {
        Toast.makeText(this, "未抓取到位置,請開啟定位服務並更新位置", Toast.LENGTH_LONG).show();
      }

    } else {
      this.location = location;
      setUpMapIfNeeded(location);
    }
  }
Ejemplo n.º 29
0
 @Override
 public void onConnected(Bundle bundle) {
   mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
   if (mLastLocation != null) {
     mLatitude = mLastLocation.getLatitude();
     mLongitude = mLastLocation.getLongitude();
     Log.d(TAG, "Location is" + " " + mLatitude + " / " + mLongitude);
   } else Log.d(TAG, "Current Location is NULL!!!!!!");
 }
Ejemplo n.º 30
0
  @Override
  public void onConnected(Bundle bundle) {
    mLocationRequest = LocationRequest.create();
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    mLocationRequest.setInterval(1000); // Update location every second

    LocationServices.FusedLocationApi.requestLocationUpdates(
        mGoogleApiClient, mLocationRequest, this);
  }