January 2013
Intermediate to advanced
408 pages
9h 23m
English
Your application needs to obtain the geographical location of the user using GPS, Wi-Fi, or cellular network triangulations.
To obtain the user’s geographical location, you need to make use of the LocationManager class together with the LocationListener interface:
package net.learn2develop.lbsgps;
import android.app.Activity;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
public class MainActivity extends Activity {
LocationManager lm;
LocationListener locationListener;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
To listen for changes in location, you need to create a class that implements the LocationListener interface:
package net.learn2develop.lbsgps;
import android.app.Activity;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;
public class MainActivity extends Activity {
LocationManager lm;
LocationListener locationListener;
private class MyLocationListener implements LocationListenerRead now
Unlock full access