Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Just few month before <strong>Google</strong> release the New and simple api for location listener.</p> <p>It's simple with a few lines of code .</p> <p>Let me explain</p> <p>Step 1:Download Google play Service library using SDK manager.Because Location service connect to the Google play.</p> <p>Step 2: Import library into your work space</p> <p>Step 3: Add library into your project</p> <p>step 4: write the following code.</p> <pre><code>public class MainActivity extends Activity { LocationClient mlocationclient; Location location; LocationRequest mlocationrequest; int trasition_type=Geofence.GEOFENCE_TRANSITION_ENTER; LocationListener mlistener; PendingIntent lviolation; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); int isGooglePlayServiceAvilable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext()); if (isGooglePlayServiceAvilable == ConnectionResult.SUCCESS) { //Create the location client mlocationclient=new LocationClient(getApplicationContext(), new CallBack(), new ConnectError()); mlocationclient.connect(); //create the location request objetcs.. mlocationrequest=LocationRequest.create().setInterval(1000).setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); //Crearte the location listener when we want to get location. mlistener=new LocationListener() { @Override public void onLocationChanged(Location location) { // TODO Auto-generated method stub Log.i("Mine Location", ""+location); } }; public class ConnectError implements GooglePlayServicesClient.OnConnectionFailedListener { @Override public void onConnectionFailed(ConnectionResult result) { // TODO Auto-generated method stub } } public class CallBack implements GooglePlayServicesClient.ConnectionCallbacks { @Override public void onConnected(Bundle connectionHint) { // TODO Auto-generated method stub location=mlocationclient.getLastLocation(); mlocationclient.requestLocationUpdates(mlocationrequest, mlistener); //new GetAddress(getApplicationContext()).execute(location); } } </code></pre> <p>Step 5: Put this code in android manifest file</p> <pre><code> &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/&gt;` &lt;meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload