Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyLocationListener implements
- GoogleApiClient.ConnectionCallbacks,
- GoogleApiClient.OnConnectionFailedListener,
- LocationListener {
- private final Context context;
- private GoogleMap mMap;
- private BreakDownOnMaps breakDownOnMaps = new BreakDownOnMaps();
- protected GoogleApiClient mGoogleApiClient;
- private LocationRequest mLocationRequest = new LocationRequest();
- public MyLocationListener(Context context) {
- this.context = context;
- buildApi();
- }
- @Override
- public void onLocationChanged(Location location) {
- breakDownOnMaps.handleNewLocation(location);
- }
- @Override
- public void onConnected(Bundle bundle) {
- System.out.println("onConnected");
- if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
- && ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
- }
- Location location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
- if (location == null) {
- LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, (com.google.android.gms.location.LocationListener) this);
- }
- else {
- breakDownOnMaps.handleNewLocation(location);
- };
- }
- private void buildApi() {
- mGoogleApiClient = new GoogleApiClient.Builder(context)
- .addConnectionCallbacks(this)
- .addOnConnectionFailedListener(this)
- .addApi(LocationServices.API)
- .build();
- }
- public void connect() {
- mGoogleApiClient.connect();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment