We provide complete mobile and web apps development solutions

Monday, August 19, 2013

Fused Location Provider android- Google I/O 2013 - Beyond the Blue Dot: New Features in Android




  Android location services are automatically maintains the user current location. Recently google released through google I/O  “Fused Location Providers”. What is the meaning of fused location?
   Taking  Gps, wifi, Mobile network, Sensors  which provides the location and taking best location out of these, By fusing these will give the better location and follows the user position continuously.


 How to implement this api to the android application?
    Android providing google play services library, which will provide the all apis which are required for implementing fused location providers.
  Location providers sends the user current location to the application through LocationClient.
Declare the permissions in the manifest.xml file
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>


Class will implement     implements
              GooglePlayServicesClient.ConnectionCallbacks,
                 GooglePlayServicesClient.OnConnectionFailedListener, LocationListener {

private LocationClient mLocationclient;


int resp = GooglePlayServicesUtil
                           .isGooglePlayServicesAvailable(getActivity());

              if (resp == ConnectionResult.SUCCESS) {
                     mLocationclient = new LocationClient(getActivity(), this, this);
                     mLocationclient.connect();
              } else {
                     GooglePlayServicesUtil.getErrorDialog(resp, getActivity(), 2);
                 }

@Override
       public void onConnected(Bundle arg0) {
              Log.i("location", "onConnected");

              if (mLocationclient != null && mLocationclient.isConnected()) {
                     Location loc = mLocationclient.getLastLocation();
                     if (loc != null) {
                     String locLatitude = "" + loc.getLatitude();
                     String locLongitude = "" + loc.getLongitude();

                                                }
else {
       LocationManager manager = (LocationManager) getActivity()
                                         .getSystemService(Context.LOCATION_SERVICE);

                           if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                                  buildAlertMessageNoGps();
                           }

                     }
              }

       }

       @Override
       public void onDisconnected() {
              Log.i("location", "onDisconnected");

       }

       @Override
       public void onConnectionFailed(ConnectionResult result) {
              Log.i("location", "onConnectionFailed");

       }

       @Override
       public void onLocationChanged(Location location) {
              if (location != null) {
                    
              String locationLatitude = "" + location.getLatitude();
              String locLongitude = "" + location.getLongitude();
              }

       }

      

0 coment�rios:

Post a Comment

Online Training

Your Name :
Your Email: (required)
Your Message: (required)

Powered by Blogger.

Recent Posts

Find Us On Facebook

Popular Posts