1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
public final class DisplayMapActivity extends MapActivity implements
LocationListener
{
private MapView mapView;
private GeoPoint p;
private MapController mc;
private MapOverlay mapOverlay = null;
private List<Overlay> listOfOverlays = null;
private double lat = 0;
private double lng = 0;
private LocationManager lm;
@SuppressWarnings("deprecation")
@Override
public final void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
mapView = (MapView) findViewById(R.id.mapView);
final LinearLayout zoomLayout = (LinearLayout) findViewById(R.id.zoom);
final View zoomView = mapView.getZoomControls();
zoomLayout.addView(zoomView, new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
mapView.displayZoomControls(true);
mc = mapView.getController();
lm = (LocationManager) this.getSystemService(LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
// Valeur par défaut car je n'arrive pas a récupérer ceux de l'initialisation (c'est cette partie que je dois remplacer par la localisation au démarrage)
lat = 48.8157060;
lng = 2.3628730;
p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
mc.animateTo(p);
mc.setCenter(p);
mc.setZoom(17);
}
/**
* Methode appeler quand la location change
*/
public void onLocationChanged(Location location)
{
lat = location.getLatitude();
lng = location.getLongitude();
Toast.makeText(getBaseContext(),
"Location change to : Latitude = " + lat + " Longitude = " + lng,
Toast.LENGTH_SHORT).show();
p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
mc.animateTo(p);
mc.setCenter(p);
mc.setZoom(17);
}
@Override
protected final boolean isRouteDisplayed()
{
return false;
}
..................
class MapOverlay extends com.google.android.maps.Overlay
{
@Override
public final boolean draw(Canvas canvas, MapView mapView, boolean shadow,
long when)
{
super.draw(canvas, mapView, shadow);
Paint paint = new Paint();
Point myScreenCoords = new Point();
mapView.getProjection().toPixels(p, myScreenCoords);
paint.setStrokeWidth(1);
paint.setARGB(255, 255, 255, 255);
paint.setStyle(Paint.Style.STROKE);
Bitmap bmp = BitmapFactory.decodeResource(getResources(),
R.drawable.marker6);
canvas.drawBitmap(bmp, myScreenCoords.x, myScreenCoords.y, paint);
canvas
.drawText("Here I am...", myScreenCoords.x, myScreenCoords.y, paint);
return true;
}
} |
Partager