Skip to content Skip to sidebar Skip to footer

Google Location Services Vs Android Location Services

As we know we have two alternates for making our applicaiton location aware Either we use Google’s Location Services API (part of Google Play services) or we use Androids Locatio

Solution 1:

You register a receiver to handle the actiion Providers_changed.

privatestaticfinalStringACTION_GPS="android.location.PROVIDERS_CHANGED";
private BroadcastReceiver yourReceiver;

privatevoidcheckGPS() {
    Contextcontext=this.getApplicationContext();
    if (context != null) {
        ButtonbtnGPS= (Button) findViewById(R.id.btnGPS);
        if (btnGPS != null) {
            LocationManagerlocationManager= (LocationManager) context
                    .getSystemService(Context.LOCATION_SERVICE);
            booleanb= locationManager
                    .isProviderEnabled(LocationManager.GPS_PROVIDER);
            locationManager = null;
            if (b) {
                if (btnGPS.getVisibility() != View.GONE) {
                    btnGPS.setVisibility(View.GONE);
                }
            } else {
                if (btnGPS.getVisibility() != View.VISIBLE) {
                    btnGPS.setVisibility(View.VISIBLE);
                }
            }
        }
    }
}

privatevoidregisterReceiverGPS() {
    if (yourReceiver == null) {
        // INTENT FILTER FOR GPS MONITORINGfinalIntentFiltertheFilter=newIntentFilter();
        theFilter.addAction(ACTION_GPS);
        yourReceiver = newBroadcastReceiver() {
            @OverridepublicvoidonReceive(Context context, Intent intent) {
                if (intent != null) {
                    Strings= intent.getAction();
                    if (s != null) {
                        if (s.equals(ACTION_GPS)) {
                            checkGPS();
                        }
                    }
                }
            }
        };
        registerReceiver(yourReceiver, theFilter);
    }
}


 @OverridepublicvoidonResume() {
 super.onResume();
 checkGPS();
 registerReceiverGPS();



    @OverridepublicvoidonStop() {
    super.onStop();
    // Do not forget to unregister the receiver!!!if (yourReceiver != null) {
        unregisterReceiver(yourReceiver);
        yourReceiver = null;
    }

Solution 2:

the google's version doesnt' provides us the state of the location provider (gps or internet)

In part, that is because it is not using any single location provider.

How would I identify the changes in the provider if I am using the google services ?

You could try listening for PROVIDERS_CHANGED_ACTION broadcasts.

Post a Comment for "Google Location Services Vs Android Location Services"