Ejemplo n.º 1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // chargement du fichier map
    File map =
        new File(
            Environment.getExternalStorageDirectory().toString() + "/Arboretum/Map/grenoble.map");
    // ajout de la map proprement
    mapView = new MapView(this);
    mapView.setMapFile(map);
    // on rend la map cliquable
    mapView.setClickable(true);
    // on rend la map zoomable
    mapView.setBuiltInZoomControls(true);
    // affichage de la map
    setContentView(mapView);
    // Creation d'un marker, un objet Drawable
    Drawable defaultMarker = getResources().getDrawable(R.drawable.letter_a);
    Drawable location = getResources().getDrawable(R.drawable.location_unoriented);
    // ici on les stock. La deuxieme liste n'est pas MyItemizdOverlay pour
    // la simple raison qu'elle va stocker notre curseur de position
    // dont on ne souhaite pas qu'il y ai de reaction si on tap dessus
    ArrayItemizedOverlay itemizedOverlay = new MyItemizedOverlay(defaultMarker, this);
    ArrayItemizedOverlay itemizedOverlay2 = new ArrayItemizedOverlay(location);
    // create a GeoPoint with the latitude and longitude coordinates
    GeoPoint myPos = new GeoPoint(0, 0);

    // create an OverlayItem with title and description
    item = new OverlayItem(Global.getArbo(), "Arboretum", "Localisation de l'arboretum.");
    item2 = new OverlayItem(myPos, "Moi", "Ma position.");
    item.setMarker(ItemizedOverlay.boundCenter(defaultMarker));
    item2.setMarker(ItemizedOverlay.boundCenter(location));
    // add the OverlayItem to the ArrayItemizedOverlay
    itemizedOverlay.addItem(item);
    itemizedOverlay2.addItem(item2);
    // Le GPS
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1, 0, this);
    sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    if (sm.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) != null) {
      // success! there's a magnetometer
    } else {
      Toast.makeText(this, "Problème d'accelerometer", Toast.LENGTH_LONG).show();
    }
    // add the ArrayItemizedOverlay to the MapView
    mapView.getOverlays().add(itemizedOverlay);
    mapView.getOverlays().add(itemizedOverlay2);
    // je me centre sur moi
    mapView.setCenter(item2.getPoint());
    // puis je zoom *2
    mapView.zoom((byte) 2, 2);
    // Récupère le root layout
    FrameLayout fl =
        (FrameLayout)
            this.getWindow().getDecorView().getRootView().findViewById(android.R.id.content);
    // Crée le bouton
    myButton = new Button(this);
    myButton.setText("Recentrer");
    myButton.setLayoutParams(
        new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    // Ajoute le bouton au layout
    fl.addView(myButton);
    myButton.setOnClickListener(this);
  }
Ejemplo n.º 2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Creation de notre map et mise en place des options liées
    File map = new File(Environment.getExternalStorageDirectory().toString() + "/campus.map");

    mapView = new MapView(this);
    mapView.setMapFile(map);
    mapView.setClickable(true);
    mapView.setBuiltInZoomControls(true);

    setContentView(mapView);

    // Creation des markers pour la position courante et pour les points d'interets
    Drawable location = getResources().getDrawable(R.drawable.location_oriented);
    Drawable draw_poi = getResources().getDrawable(R.drawable.location);

    // On le stock dans un tableau seul car on ne le veut pas cliquable
    ArrayItemizedOverlay itemizedOverlay_location = new ArrayItemizedOverlay(location);

    // Initialisation du GPS au niveau du soleil
    GeoPoint myPos = new GeoPoint(45.194218, 5.777244);

    // Creation du tableau de marker pour les points d'interets
    ArrayItemizedOverlay itemizedOverlay_POI =
        new ItemizedOverlay_POI(ItemizedOverlay.boundCenter(draw_poi), this);

    // Mise à jour du marker de position courante
    MarkerLocation = new OverlayItem(myPos, "Moi", "Je suis ici");
    MarkerLocation.setMarker(ItemizedOverlay.boundCenter(location));

    itemizedOverlay_location.addItem(MarkerLocation);
    mapView.setCenter(MarkerLocation.getPoint());

    // On ajoute ici les planètes et les plantes dans le itemized Overlay une par une
    itemizedOverlay_POI.addItem(
        new OverlayItem(Description.getSoleil(), "Soleil", "Emplacement du Soleil"));
    itemizedOverlay_POI.addItem(
        new OverlayItem(Description.getMarre(), "Mare", "Emplacement de la Mare"));
    itemizedOverlay_POI.addItem(
        new OverlayItem(Description.getMercure(), "Mercure", "Emplacement de Mercure"));
    itemizedOverlay_POI.addItem(
        new OverlayItem(Description.getVenus(), "Venus", "Emplacement de Venus"));
    itemizedOverlay_POI.addItem(
        new OverlayItem(Description.getTerre(), "Terre", "Emplacement de Terre"));
    itemizedOverlay_POI.addItem(
        new OverlayItem(Description.getMars(), "Mars", "Emplacement de Mars"));
    itemizedOverlay_POI.addItem(
        new OverlayItem(Description.getJupiter(), "Jupiter", "Emplacement de Jupiter"));
    itemizedOverlay_POI.addItem(
        new OverlayItem(Description.getSaturne(), "Saturne", "Emplacement de Saturne"));
    itemizedOverlay_POI.addItem(
        new OverlayItem(Description.getUranus(), "Uranus", "Emplacement de Uranus"));
    itemizedOverlay_POI.addItem(
        new OverlayItem(Description.getMeleze(), "Meleze", "Emplacement de Meleze"));
    itemizedOverlay_POI.addItem(
        new OverlayItem(Description.getMahonia(), "Mahonia", "Emplacement de Mahonia"));

    // Mise en place de l'utilisation du GPS
    this.location = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    this.location.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1, 0, this);

    // On ajoute les markers dans la mapview
    mapView.getOverlays().add(itemizedOverlay_POI);
    mapView.getOverlays().add(itemizedOverlay_location);
  }