Jump to content

Problème développement appli GoogleMap


laura69
 Share

Recommended Posts

Bonjour,

J'ai un problème dans la compilation de mon projet googleMap sous Eclipse (android).

Mon projet permet de géolocaliser instantanément ma position, trace mon trajet sur un googleMap, affiche la vitesse instantanée et la distance parcourue.

Si quelqu'un a la possibilité de m'aider, ce serait vraiment super !! Car je tourne en rond depuis un bout de temps.

L'émulateur ne se lance pas.

Voici mes fichiers sources:

 "MapActivity"

import java.util.ArrayList;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.Point;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
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.Projection;

public class GpsGoogleMapActivity extends MapActivity {
protected MapView map;
protected MapController mapController;
protected GeoPoint pointAvt = null;
protected ArrayList<GeoPoint> geoPoints = new ArrayList<GeoPoint>();
protected ArrayList<Location> loc = new ArrayList<Location>();
protected double distance= 0;

   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    map = (MapView) findViewById(R.id.map);
    mapController = map.getController();

    PositionCouranteListener positionListener = new PositionCouranteListener(this);
    LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, positionListener);

    GeoPoint point = this.dernierePositionConnue();
    geoPoints.add(point); // Ajout des geopoints à l'arrayList:geopoints
    mapController.setCenter(point);
    mapController.setZoom(17);
    mapController.animateTo(point);
    map.invalidate();

   }

   public GeoPoint dernierePositionConnue(){
 LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
 Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
 loc.add(location); //ajout de la location à l'arrayList:loc
 location.getSpeed(); // Vitesse instantannée, à afficher dans le textView correspondant
 GeoPoint point = new GeoPoint ((int)(location.getLatitude()*1E6),(int)(location.getLongitude()*1E6));
 return point;
   }

   public void changerPosition(GeoPoint point){
 map.getController().setCenter(point);
 map.invalidate();
   }

   /* Méthode pour Tracer le chemin
 *
 */
   public void draw(Canvas canvas, MapView map, boolean shadow) {

 Projection projection = map.getProjection();

    Path p = new Path();
    for (int i = 0; i < geoPoints.size(); i++) {
    if (i == geoPoints.size() - 1) {
	    break;
    }
    Point from = new Point();
    Point to = new Point();
    projection.toPixels(geoPoints.get(i), from);
    projection.toPixels(geoPoints.get(i + 1), to);
    p.moveTo(from.x, from.y);
    p.lineTo(to.x, to.y);
    }
    Paint mPaint = new Paint();
    mPaint.setStyle(Style.FILL);
    mPaint.setColor(0xFFFF0000);
    mPaint.setAntiAlias(true);
    canvas.drawPath(p, mPaint);

   }

   /* Calcul la distance parcourue
 *
 */
   public double distanceParcourue(){
 for( int i=0; i < loc.size(); i++ ){
  distance= distance + (loc.get(i).distanceTo(loc.get(i+1)));
 }
 return distance;
   }

   @Override
 protected boolean isRouteDisplayed() {
  // TODO Auto-generated method stub
  return false;
 }
}

2eme fichier:

import com.google.android.maps.GeoPoint;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
import android.widget.Toast;
public class PositionCouranteListener implements LocationListener {

protected GpsGoogleMapActivity maps;

public PositionCouranteListener(GpsGoogleMapActivity maps) {
 this.maps = maps;

}

@Override
public void onLocationChanged(Location location) {
 GeoPoint point = new GeoPoint((int)(location.getLatitude()*1E6),(int)(location.getLongitude()*1E6));
  maps.changerPosition(point);
}


@Override
public void onProviderDisabled(String provider){
 Toast.makeText(maps, "gpsdésactivé", Toast.LENGTH_LONG);
}

@Override
public void onProviderEnabled(String provider){
 Toast.makeText(maps, "gps activé", Toast.LENGTH_LONG);
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
 // TODO Auto-generated method stub
}
}

D'avance je vous remercie.

J'ai vraiment besoin d'aide !!!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...