Tracer le parcours sur une carte GoogleMaps et l'enregistrer dans une base SQLite
Bonjour,
J'ai un problème pour tracer le parcours sur une carte Google Maps.
J'arrive à tracer un marqueur à chaque déplacement mais je n'arrive pas à tracer le parcours de déplacement.
Voilà mon code :
userposition.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.google.android.maps.MapView
android:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="0sPCJp3rwAFa842Qz1Lb_CezFZIVpa1mpWScXrw"
/>
<LinearLayout android:id="@+id/zoom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>
</LinearLayout> |
userposition.java
Code:
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
| package com.anis.telgps;
import java.util.ArrayList;
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.KeyEvent;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;
public class userposition extends MapActivity implements LocationListener {
TextView txtInfo;
private MapView mapView = null;;
private LocationManager lm = null;;
private double lat = 0;
private double lng = 0;
private MapController mc = null;
// private Projection projection;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.userposition);
mapView = (MapView) this.findViewById(R.id.mapView);
mapView.setBuiltInZoomControls(true);
lm = (LocationManager) this.getSystemService(LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 0, this);
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000, 0, this);
mc = mapView.getController();
mc.setZoom(17);
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_S)
{
mapView.setSatellite(!mapView.isSatellite());
return true;
}
return super.onKeyDown(keyCode, event);
}
public final void onLocationChanged(Location location)
{
lat = location.getLatitude();
lng = location.getLongitude();
Toast.makeText(getBaseContext(),
"Place change à : Latitude = " + lat + " Longitude = " + lng,
Toast.LENGTH_SHORT).show();
GeoPoint p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
mc.animateTo(p);
mc.setCenter(p);
MonOverlay object = new MonOverlay(getResources().getDrawable(R.drawable.map2)) ;
object.addpoint(p);
mapView.getOverlays().add(object);
mapView.setTraffic(true);
mapView.setSatellite(true);
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
public class MonOverlay extends ItemizedOverlay<OverlayItem>{
List<GeoPoint> points = new ArrayList<GeoPoint>();
public MonOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
// TODO Auto-generated constructor stub
}
@Override
protected OverlayItem createItem(int i) {
GeoPoint point = points.get(i);
return new OverlayItem(point,"Titre","description");
}
@Override
public int size() {
return points.size();
}
public void addpoint(GeoPoint point){
this.points.add(point);
populate();
}
}
} |
Autrement dit, j'arrive à tracer des points qui ne sont pas continus sur la carte comme ceci :
Point départ. ... ... . . Point d'arrivée
Mais ce que je cherche c'est la résultat suivant:
Point départ________________ Point d'arrivée
Je ne sais pas comment faire pour enregistrer le parcours d'un voyageur d'une carte Google Maps, dans une table SQLite.
Voici un exemple de parcours
https://encrypted-tbn0.gstatic.com/i...rOet1XTP1F92ol
Quelqu'un saurait-il m'indiquer comment procéder ?
Merci d'avance pour votre aide.