Eclipse Mobile Mousw Przewodnik Instalacji Strona 30

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 59
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 29
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();
Przeglądanie stron 29
1 2 ... 25 26 27 28 29 30 31 32 33 34 35 ... 58 59

Komentarze do niniejszej Instrukcji

Brak uwag