Installation guide

30
Section 3 Locate Your Position with Built-in GPS
Use built-in Android GPS by copying the following code in the class of public void
onCreate(Bundle savedInstanceState){}.
/* Use the LocationManager class to obtain GPS locations */
mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5*1000, 10,
mlocListener);
Define necessary variables; specifically Lon and Lat are longitude and latitude of the built-in
GPS location.
double Lon = 0;
double Lat = 0;
private LocationManager mlocManager;
private LocationListener mlocListener = new MyLocationListener();
private MyOverlay myOverlay = new MyOverlay(null);
Physically create a class of MyLocationListenor and add unimplemented methods as follows.
class MyLocationListener implements LocationListener{…}
Physically create a class of MyOverlay and add constructor and unimplemented methods as
follows.
Edit the method when location is changed in onLocationChanged as follows.
public void onLocationChanged(Location location)
{
Lon = location.getLongitude();
Lat = location.getLatitude();
point = new GeoPoint((int)(Lat*1e6), (int)(Lon*1e6));
mapView.getOverlays().add(myOverlay);
mapController.animateTo(point);
}
Edit the method of updating the geo-point when location is changed in onDraw() as follows.
protected void onDraw(Canvas arg0, MapView arg1)
{
Paint paint = new Paint();
paint.setColor(Color.RED);
Point screenPoint = new Point();