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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
package com.mti.android;
import java.util.List;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import com.google.android.maps.MapView.LayoutParams;
public class GoogleMapMainActivity extends MapActivity implements
LocationListener {
private MapView mapView;
private double lat = 0;
private double lng = 0;
private LocationManager lm;
private MapController mc;
private GeoPoint p;
private List mapOverlays;
//private MapItemizedOverlay itemizedoverlay;
/** Called when the activity is first created. */
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// On recupere la vue
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));
// On affiche le zoom controle et l'affichage street view de la carte
mapView.displayZoomControls(true);
mc = mapView.getController();
// Creation du geo point
mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.marker6);
// itemizedoverlay = new MapItemizedOverlay(drawable, this);
lm = (LocationManager) this.getSystemService(LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
lat = 48.8157060;
lng = 2.3628730;
p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
mc.animateTo(p);
mc.setCenter(p);
mc.setZoom(17);
}
@Override
protected boolean isRouteDisplayed()
{
// TODO Auto-generated method stub
return false;
}
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);
}
//A faire si nécessaire, gestion du cas quand il y a désactivation de l'opérateur
public void onProviderDisabled(String arg0)
{
// TODO Auto-generated method stub
}
//A faire si nécessaire, gestion du cas quand il y a réactivation de l'opérateur
public void onProviderEnabled(String arg0)
{
// TODO Auto-generated method stub
}
public void onStatusChanged(String arg0, int arg1, Bundle arg2)
{
// TODO Auto-generated method stub
}
/** Creation du menu */
@Override
public final boolean onCreateOptionsMenu(Menu menu)
{
final MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.menu_mapdisplay, menu);
return true;
}
/** Handler sur le menu */
@Override
public final boolean onOptionsItemSelected(MenuItem item)
{
// Button "Voir ses panneaux"
if (item.getItemId() == R.id.poserMarqueur)
{
Toast.makeText(getBaseContext(),
"Ajout du panneau",
Toast.LENGTH_SHORT).show();
OverlayItem overlayitem = new OverlayItem(p,"nom du panneau", "description du panneau");
// itemizedoverlay.addOverlay(overlayitem);
//mapOverlays.add(itemizedoverlay);
}
else if (item.getItemId() == R.id.annuler)
{
// Cas du bouton Annuler
}
return super.onOptionsItemSelected(item);
} |
Partager