Gqf

//fcffi "fölflS" Btt GPS ftJMftlSA

Im (Locat ionManager) getSystemService (Context. LOCATION_SERVICF.) ; 1ocationListener = new MyLocationListener();

Im.requestLocationUpdates(LocationManager.GPS PROVIDER, 0, 0, locationListener);

ft kyk LocationManager? r D : Android «t» LocationManager 7 fe

" /X Vx j Ji*äflff/ä^^g«^ LocationProvider W«ÜBttftiilJE i «r; Intent

I mMapView - (MapView) findViewByld(R.id.mv); mc mMapView.getController(); mc. set:Zoom (10) ;

'M ^iit^l&ftiklUfrirpft MapView, iK/Stttfj getController ^ MapController,

^W*ti*^MapController (setZoom) fKHSffc'.

lm (LocationManager) getSystemService(Context.LOCATION_SEPVICE); locationListener = new MyLocationListener();

lm.requestLocationUpdates(LocationManager.GPS PROVIDER, 0, 0, locationListener> ;

h^^^^aLftltii^^ftlfe^r, KM y- locationListener ft MyLocationListener, f'Kj

ItAGPS^'M^ftHiM^^M^ilJo % r MyLocationListener ft&X, in ifil & F5fe«t public void panWestO <

GeoPoint pt « new GeoPoint(mMapView.getMapCenter().getLatitudeE6(), mMapView.getMapCenter().getLongitudeE6()

public void panEast() (

GeoPoint pt = new GeoPoint (mMapView. getMapCenter {) .getLati t.udeE6 () , mMapView.getMapCenter().getLongitudeE6() i mMapView.getLcngitudeSpan() / 4);

publir. void panNorthO {

GeoPoinr pt = new GeoPoint (mMapView .getMapCenter ().get Lati tudeE6 () » mMapView. getLatitudeSpar. () / 4, mMapView.getMapCenter () .getLongitudeE6() ) ; mc. setCenter(pt); )

public void panSouthO (

GeoPoint pt = new GeoPoint(mMapView.getMapCenter().getLatitudeE6()

- mMapView.getLatitudeSpan() / 4, mMapView.getMapCenter() .getLongitudeE6() ) ;

public void zoomlnO (

public void zoornOutO I mc.zoomOut(); )

ittii MapController 'f tiSHiftW

£ 13 M Android —-Google Map public void toggleSatellite () { mMapView. setSatel 1 i ~e (true) ; mMapView.setStreetView(Halse); mMapView.setTraff ic(false); \

public void toggleTraffic() { mMapView.setTraf fic(true); mMapView.setSatellite(false); mMapView.setStreetView(false); )

public void LoggleStreetView() ( mMapView.setSt reetView< true) ; mMapView.setSatellite(false); mMapView.setTraf f ic(false); )

^ iWUHh lämffiStftKWft. sctStrectVicw(tnicM^A«»M«0rW®/^, fifiifif Google Map ffi *WfVü?f-.

$ Fife "tÄbbiStfiftWA'ifc. IkKJE^a "GPS" ccntciOnGPSPosition. tt

11 GPS »SttfiLW. sfcSMViin FW/K:

private void cer.terOnGPSPosition () I Log.d(TAG, "centerOnGPSPosition"); String provider - "gps";

LocationManager lm = (LocationManager) getSystemService(Context.LOCATION SERVICE);

Location loc lm.getLastKnownLocation(provider); loc = lm.getLastKnownLccation(provider);

mDefPoint = new GeoPoint((int) (loc.getLatitude() * 1000000), (int) (loc.getLongitude() * 1000000)); mDefCaption = "I'm Here."; mc.animaleTo(mDefPoint) ; mc.setCenter(mDefPoint); //& Overlay S7FflEJfeffl± . MyOverlay mo - new MyOverlay(); mo.onTap(mDefPoint, mMapView);

mMapView.getOverlays().add(mo); >

LocationManager »S^ffiTtt GPS ftSt^Ä. «JBttttSfcttJfcti, iM$JTJ & J" Overlay ffi MyOverlay * T* MyOverlay fW'i-il» Fffii^&WiiJ*

ÖJ-fÜMftffl T GPS iPGoogleMap,^rW,ÄS4 manifest +frAttÄ,

<uses-pertt,iss ion android:name="android.permi s si on.INTERNET"x/u se s-permission > <uses-permission android:name="android.permission.ACCESS FINE LOCATION"></uses-permission>

Kl« -TflifBifstitJHW MyOverlay ÄWftPiin tff\'T<:

// This is used draw an overlay on the map protected class KyOverlay extends Overlay ( @Override public void draw(Canvas canvas, MapView mv, boolean shadow) \ Loq .d (TAG, "MyOverlay::darw..mDefCaption=" »• mDefCaption); super.draw(canvas, mv, shadow);

Paint p = new Paint(); int(] scoords new int|2|; irit sz = 5;

Point myScreenCoords = new Point. () ;

mMapView.getProject ion() .toPixels(mDefPoint, myScreenCoords); //

scoords[0 J = myScreenCoords.x; scoords|11 - myScreenCoords.y; p.setTextSize(14); p.setAntiAlias(true);

int sw (int) (p.measureText(mDefCaption) + 0..rjf); int. sh = 25;

int sx scoordsfO] - sw / 2 - 5; int sv = scoords[1] - sh - sz 2;

RectF rec = new RectF(sx, sy, sx \ sw + 10, sy + sh);

canvas.drawRoundRect(rec, 5, 5, p);

p.setStyle(Style.STROKE); p.setARGB(255, 255, 255, 255); canvas.drawRbundRect(rec, 5, 5, p);

Canvas.drawText(mDefCaption, sx ♦ 5, sy + sh - 8, p);

p.setStyle(Style.FILL); p.setARGB(88, 255, 0, 0) ; p. setStrokeWidth(1) ;

Rect F spot = new RectF(scoords[0] - sz, scoordsLI! + sz, scoords[0] » sz, scoords[1) - sz); canvas.drawOval(spot, p) ;

p.setARGB(255, 255, 0, 0); p. setStyle(Style.STROKE);

canvas.drawCircle(scoords[01, scoords|1], sz, p); )

Android 'I'M Overlay l^WiffiK draw ML* /''I' "tfifciifl] toPixels ft GPS Geopoint h T-tfLW & kfll^te myScreenCoords , Android fi-J draw n 13 S Android S^Uffil--& Google Map tfÄ^AIMbifeEB

iiiin -^l'S^aWJänül&MiffllW MyLocationListener ,

private class MyLocationListener implements LocationListener I Ii?Over ride public void onLocationChanged(Location loc) {

Log.d(TAG, "MyLocationListener::onLocationChanged..");

Toast.makeText (

götBaseContext0,

"Location changed : Lat: " + loc.getLatitude() + " Lng: " + loc.getLongitude(), Toast.LENGTH SHORT).show();

mDefPoint = new GeoPoint((int) (loc.getLatitude() * 1000000), (int) (loc.getLongitude() * 1000000)); mc.animateTo(mDefPoint); mc.setCenter(mDefPoint);

//mmim mDetCaption = "Lat: " + loc.getLatitude() t " Lng: " + loc.getLongitude();

MyOverlay mo = new MyOverlayO;

mMapView.getOverlays().add(mo);

Was this article helpful?

0 0

Post a comment