IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

Affichage d'un itinéraire


Sujet :

Android

  1. #1
    Membre du Club
    Femme Profil pro
    Etudiante
    Inscrit en
    Février 2013
    Messages
    95
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Etudiante
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Février 2013
    Messages : 95
    Points : 68
    Points
    68
    Par défaut Affichage d'un itinéraire
    Bonjour,
    J'ai essayée de dessiner un itinéraire entre deux points sur la carte google map .
    Voila mon code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    package com.example.projet_fin_etude;
     
    import java.io.IOException;
    import java.net.HttpURLConnection;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.ArrayList;
    import java.util.List;
     
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
     
    import org.json.JSONObject;
    import org.w3c.dom.Document;
    import org.xml.sax.SAXException;
     
    import com.google.android.maps.GeoPoint;
    import com.google.android.maps.MapActivity;
    import com.google.android.maps.MapView;
    import com.google.android.maps.Overlay;
    import com.google.android.maps.OverlayItem;
     
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.provider.ContactsContract.Data;
    import android.app.Activity;
    import android.content.Context;
    import android.content.Intent;
    import android.content.pm.ActivityInfo;
    import android.graphics.Bitmap;
    import android.graphics.Color;
    import android.graphics.drawable.Drawable;
    import android.util.Log;
    import android.view.Menu;
    import android.view.Window;
     
    public class MapDirection extends MapActivity{
     
    	  MapView mapview;
    	  MapRouteOverlay mapoverlay;
    	  Context _context;
    	  List<Overlay> maplistoverlay;
    	  Drawable drawable,drawable2;
    	  MapOverlay mapoverlay2,mapoverlay3;
    	  GeoPoint srcpoint,destpoint;
    	  Overlay overlayitem;
    	  ArrayList <Place> myList =new ArrayList <Place>();
    	  double lt;
    		double lg;
    	  public void onCreate(Bundle savedInstanceState){
    	    super.onCreate(savedInstanceState);
    	    requestWindowFeature(Window.FEATURE_NO_TITLE);  
    	    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    	    setContentView(R.layout.activity_map_direction);
     
    	    mapview=(MapView)this.findViewById(R.id.mapView);
    	    Intent intent = getIntent();
    		Bundle extras =intent.getExtras();
    		if (extras != null){
    			this.myList = (ArrayList<Place>) extras.getSerializable("myList");
    			 lt=Double.parseDouble(intent.getStringExtra("latitude"));
    			 lg=Double.parseDouble(intent.getStringExtra("longitude"));
     
    	    callMap();
    		}
    	  }
    	  private void callMap() {
     
     
    	    srcpoint=new GeoPoint((int)(lt*1E6),(int)(lg*1E6));
    	    maplistoverlay=mapview.getOverlays();
    	    drawable=this.getResources().getDrawable(R.drawable.marq_dest);
    	    mapoverlay2=new MapOverlay(drawable);
    	    OverlayItem overlayitem = new OverlayItem(srcpoint, "", "");
    	    mapoverlay2.addOverlay(overlayitem);
    	    maplistoverlay.add(mapoverlay2);
     
    	    destpoint=new GeoPoint((int)(myList.get(0).getLatitude()*1E6),(int)(myList.get(0).getLongitude()*1E6));
    	    drawable2=this.getResources().getDrawable(R.drawable.marqueur1);
    	    mapoverlay3=new MapOverlay(drawable2);
    	    OverlayItem overlayitem3 = new OverlayItem(destpoint, "", "");
    	    mapoverlay3.addOverlay(overlayitem3);
    	    maplistoverlay.add(mapoverlay3);
     
     
    	    double dest_lat = myList.get(0).getLatitude();
    	    double dest_long = myList.get(0).getLongitude();
     
    	    GeoPoint srcGeoPoint = new GeoPoint((int) (lt* 1E6),
    	        (int) (lg * 1E6));
    	    GeoPoint destGeoPoint = new GeoPoint((int) (dest_lat * 1E6),
    	        (int) (dest_long * 1E6));
     
    	  new DrawPath(srcGeoPoint, destGeoPoint, Color.BLUE, mapview).execute();
     
    	    mapview.getController().animateTo(srcGeoPoint);
    	    mapview.getController().setZoom(13);
    	    //mapview.setStreetView(true);
    	    mapview.setBuiltInZoomControls(true);
    	    mapview.invalidate();
     
     
    	  }
    	  class DrawPath  extends AsyncTask<Void, Void, Document>
    	       {
     
    		  GeoPoint src;
    		  GeoPoint dest;
    		  int color;
    		  MapView mMapView01;
    		  public DrawPath(GeoPoint src, GeoPoint dest, int color,
    			      MapView mMapView01) 
    		  {
     
    			  this.src=src;
    			  this.dest=dest;
    			  this.color=color;
    			  this.mMapView01=mMapView01;
     
     
    		  }
     
     
     
     
    	    //System.out.println(urlString);
    	    // get the kml (XML) doc. And parse it to get the coordinates(direction route).
     
     
    	    	@Override
    			protected Document doInBackground(Void... params) {
     
    	    		//System.out.println(urlString);
    	    	    // get the kml (XML) doc. And parse it to get the coordinates(direction route).
    	    		Document doc = null;
    	    	    HttpURLConnection urlConnection= null;
    	    	    URL url = null;
    	    	    // connect to map web service
    	    	    StringBuilder urlString = new StringBuilder();
    	    	    urlString.append("http://maps.google.com/maps?f=d&hl=en");
    	    	    urlString.append("&saddr=");//from
    	    	    urlString.append( Double.toString((double)src.getLatitudeE6()/1.0E6 ));
    	    	    urlString.append(",");
    	    	    urlString.append( Double.toString((double)src.getLongitudeE6()/1.0E6 ));
    	    	    urlString.append("&daddr=");//to
    	    	    urlString.append( Double.toString((double)dest.getLatitudeE6()/1.0E6 ));
    	    	    urlString.append(",");
    	    	    urlString.append( Double.toString((double)dest.getLongitudeE6()/1.0E6 ));
    	    	    urlString.append("&ie=UTF8&0&om=0&output=kml");
    	    	    Log.d("xxx","URL="+urlString.toString());
     
     
    	    try
    	    {
    	      url = new URL(urlString.toString());
    	      urlConnection=(HttpURLConnection)url.openConnection();
    	      urlConnection.setRequestMethod("GET");
    	      urlConnection.setDoOutput(true);
    	      urlConnection.setDoInput(true);
    	      urlConnection.connect();
     
    	      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    	      DocumentBuilder db = dbf.newDocumentBuilder();
    	      doc = db.parse(urlConnection.getInputStream());
    	    }
    	    catch (MalformedURLException e)
    	    {
    	      e.printStackTrace();
    	    }
    	    catch (IOException e)
    	    {
    	      e.printStackTrace();
    	    }
    	    catch (ParserConfigurationException e)
    	    {
    	      e.printStackTrace();
    	    }
    	    catch (SAXException e)
    	    {
    	      e.printStackTrace();
    	    }
    	    return doc;
    	    	}
    	    	  protected void onPostExecute(Document result){
     
    	      if(result.getElementsByTagName("GeometryCollection").getLength()>0)
    	      {
    	        //String path = doc.getElementsByTagName("GeometryCollection").item(0).getFirstChild().getFirstChild().getNodeName();
    	        String path = result.getElementsByTagName("GeometryCollection").item(0).getFirstChild().getFirstChild().getFirstChild().getNodeValue() ;
    	        Log.d("xxx","path="+ path);
    	        String [] pairs = path.split(" ");
    	        String[] lngLat = pairs[0].split(","); // lngLat[0]=longitude lngLat[1]=latitude lngLat[2]=height
    	        // src
    	        GeoPoint startGP = new GeoPoint((int)(Double.parseDouble(lngLat[1])*1E6),(int)(Double.parseDouble(lngLat[0])*1E6));
    	        //mMapView01.getOverlays().add(overlayitem);
    	        GeoPoint gp1;
    	        GeoPoint gp2 = startGP;
    	        for(int i=1;i<pairs.length;i++) // the last one would be crash
    	        {
    	          lngLat = pairs[i].split(",");
    	          gp1 = gp2;
    	          // watch out! For GeoPoint, first:latitude, second:longitude
    	          gp2 = new GeoPoint((int)(Double.parseDouble(lngLat[1])*1E6),(int)(Double.parseDouble(lngLat[0])*1E6));
    	          mMapView01.getOverlays().add(new MapRouteOverlay(gp1,gp2,2,color));
    	          Log.d("xxx","pair:" + pairs[i]);
    	        }
    	        //mMapView01.getOverlays().add(new MapRouteOverlay(dest,dest, 3)); // use the default color
    	      }
    	    }
     
     
     
    	  }
    	  @Override
    	    protected boolean isRouteDisplayed() {
    	      // TODO Auto-generated method stub
    	      return false;
    	    }
    	}
    La carte s'affiche ainsi que les deux marqueurs mais l'activité s’arrête et l'itinéraire ne s'affiche pas et j'obtient ces erreurs dans le logcat:

    04-28 21:51:53.544: W/System.err(922): org.xml.sax.SAXParseException: expected: /meta read: noscript (position:END_TAG </noscript>@1:493 in java.io.InputStreamReader@40f77098)
    04-28 21:51:53.554: W/System.err(922): at org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:146)
    04-28 21:51:53.554: W/System.err(922): at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:107)
    04-28 21:51:53.554: W/System.err(922): at com.example.projet_fin_etude.MapDirection$DrawPath.doInBackground(MapDirection.java:165)
    04-28 21:51:53.575: W/System.err(922): at com.example.projet_fin_etude.MapDirection$DrawPath.doInBackground(MapDirection.java:1)
    04-28 21:51:53.575: W/System.err(922): at android.os.AsyncTask$2.call(AsyncTask.java:287)
    04-28 21:51:53.575: W/System.err(922): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
    04-28 21:51:53.604: W/System.err(922): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
    04-28 21:51:53.604: W/System.err(922): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
    04-28 21:51:53.604: W/System.err(922): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
    04-28 21:51:53.624: W/System.err(922): at java.lang.Thread.run(Thread.java:856)
    04-28 21:51:53.624: D/AndroidRuntime(922): Shutting down VM
    Avez vous des idées s'il vous plait? et merci bien d'avance .

  2. #2
    Expert éminent

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Points : 9 149
    Points
    9 149
    Par défaut
    Bonjour,

    TU as une erreur sur ton parser.

    Montre nous le fichier xml que tu récupères ?
    Responsable Android de Developpez.com (Twitter et Facebook)
    Besoin d"un article/tutoriel/cours sur Android, consulter la page cours
    N'hésitez pas à consulter la FAQ Android et à poser vos questions sur les forums d'entraide mobile d'Android.

  3. #3
    Membre du Club
    Femme Profil pro
    Etudiante
    Inscrit en
    Février 2013
    Messages
    95
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Etudiante
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Février 2013
    Messages : 95
    Points : 68
    Points
    68
    Par défaut
    Bonjour Feanorin,
    Merci bien pour votre réponse.
    Je suis habitué à travailler avec Json .
    Je peut vous envoyer les valeurs de latitude et longitude des points .
    src=(37.422005,-122.084095)
    dest=(37.422171,-122.084716)
    et merci beaucoup.

  4. #4
    Membre du Club
    Femme Profil pro
    Etudiante
    Inscrit en
    Février 2013
    Messages
    95
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Etudiante
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Février 2013
    Messages : 95
    Points : 68
    Points
    68
    Par défaut
    Bonjour,
    Je n'arrives pas à récupérer le fichier xml mais j'ai testée l'url que j'utilises dans mon code dans le navigateur et j’obtiens l’itinéraire entre mes deux points dessiné sur google map .
    Avez vous des idées s'il vous plait ???

  5. #5
    Expert éminent

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Points : 9 149
    Points
    9 149
    Par défaut
    Essaye de voir ce que tu récupère dans l'inputStream et poste le nous.
    Responsable Android de Developpez.com (Twitter et Facebook)
    Besoin d"un article/tutoriel/cours sur Android, consulter la page cours
    N'hésitez pas à consulter la FAQ Android et à poser vos questions sur les forums d'entraide mobile d'Android.

  6. #6
    Membre du Club
    Femme Profil pro
    Etudiante
    Inscrit en
    Février 2013
    Messages
    95
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Etudiante
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Février 2013
    Messages : 95
    Points : 68
    Points
    68
    Par défaut
    Bonjour,
    Merci beaucoup Feanorin.
    Voila ce que j’obtiens dans l'inputstream :
    "libcore.net.http.ChunkedInputStream@40e02298".
    Et merci bien pour votre aide .

  7. #7
    Expert éminent

    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Février 2007
    Messages
    4 253
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2007
    Messages : 4 253
    Points : 7 618
    Points
    7 618
    Billets dans le blog
    3
    Par défaut
    Non ça ce n'est pas le contenu de l'InputStream, mais le "toString()" (représentation textuelle) de l'instance InputStream.
    Comme dans 96% des cas (à part Number, String, StringBuffer et autres), toString() renvoie juste le nom de la classe et sa position mémoire.
    N'oubliez pas de cliquer sur mais aussi sur si un commentaire vous a été utile !
    Et surtout

  8. #8
    Membre du Club
    Femme Profil pro
    Etudiante
    Inscrit en
    Février 2013
    Messages
    95
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Etudiante
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Février 2013
    Messages : 95
    Points : 68
    Points
    68
    Par défaut
    Bonjour,
    OK, comment peut on donc récupérer la valeur de l'inputstream???

  9. #9
    Expert éminent

    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Février 2007
    Messages
    4 253
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2007
    Messages : 4 253
    Points : 7 618
    Points
    7 618
    Billets dans le blog
    3
    Par défaut
    Non mais de toute manière il y a une erreur dans le fichier....
    Le parser SAX dit: "j'attends une balise </meta> et j'ai une balise <noscript>"
    (si j'ai bien compris le message).

    Donc affichez déjà l'URL en debug... puis tapez l'url dans un browser pour récupérer le fichier, et collez le ici.

    Ensuite évitez les blocs de catch inutiles

    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
     
    Document doc; // pas d'initialisation de doc, le compilateur nous avertira si un "chemin" oublie de le mettre à jour, très utile pour les valeurs de retour
    try {
        URL url = new URL(urlString.toString()); // pas besoin de déclarer URL en dehors du bloc
        HttpURLConnection urlConnection= (HttpURLConnection) url.openConnection(); // pareil ici, inutile d'exposer urlConnection à l'exterieur
        urlConnection.setRequestMethod("GET");
        urlConnection.setDoOutput(true);
        urlConnection.setDoInput(true); // vraiment ? on va passer des données ?
        urlConnection.connect();
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        doc = db.parse(urlConnection.getInputStream());
    } catch (Exception ex) { // <= on récupère *toutes* les exceptions !
        Log.e("MapDirection","Failed to retrieve XML data",ex);
        doc = null;
    }
    return doc;
    N'oubliez pas de cliquer sur mais aussi sur si un commentaire vous a été utile !
    Et surtout

  10. #10
    Membre du Club
    Femme Profil pro
    Etudiante
    Inscrit en
    Février 2013
    Messages
    95
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Etudiante
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Février 2013
    Messages : 95
    Points : 68
    Points
    68
    Par défaut
    Bonjour,
    Merci bien pour vos conseils.
    J'ai déjà taper l'url dans le browser .Je n'obtiens pas un fichier mais j'obtiens la carte google map sur laquelle l'itinéraire entre mes deux points est dessiné.
    Merci beaucoup si vous pouvez m'aider de plus.

  11. #11
    Membre du Club
    Femme Profil pro
    Etudiante
    Inscrit en
    Février 2013
    Messages
    95
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Etudiante
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Février 2013
    Messages : 95
    Points : 68
    Points
    68
    Par défaut
    Bonjour,
    Si vous avez des idées , n'hésitez pas de m'aider s'il vous plait .
    Lorsque j'exécutes mon code ,il m'affiches la carte Google maps et les deux marqueurs sur les deux points puis l'exécution s’arrête .
    Je testes l'url dans le navigateur et j’obtiens l’itinéraire correctement ,
    je n'arrives pas à comprendre l'erreur de mon code ??
    Aidez moi s'il vous plait et merci d'avance .

  12. #12
    Membre du Club
    Femme Profil pro
    Etudiante
    Inscrit en
    Février 2013
    Messages
    95
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Etudiante
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Février 2013
    Messages : 95
    Points : 68
    Points
    68
    Par défaut
    Bonjour tout le monde,
    J'ai essayée avec un autre code pour afficher l'itinéraire .

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    package com.example.projet_fin_etude;
     
    import java.net.URL;
    import java.util.ArrayList;
     
    import javax.xml.parsers.SAXParser;
    import javax.xml.parsers.SAXParserFactory;
     
    import org.xml.sax.InputSource;
    import org.xml.sax.XMLReader;
     
    import android.content.Intent;
    import android.graphics.Bitmap;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.util.Log;
     
    import com.example.projet_fin_etude.KMLHandler;
    import com.example.projet_fin_etude.R;
    import com.example.projet_fin_etude.RouteOverlay;
    import com.google.android.maps.GeoPoint;
    import com.google.android.maps.MapActivity;
    import com.google.android.maps.MapView;
     
    public class MapDirection extends MapActivity  {
    	private MapView mapView;
    	ArrayList <Place> myList =new ArrayList <Place>();
    	double lt;
    	double lg;
    	  GeoPoint srcGeoPoint;
    	  GeoPoint destGeoPoint;
          int pos;
    	@Override
    	protected boolean isRouteDisplayed() { return false; }
     
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
     
            setContentView(R.layout.activity_map_direction);
            mapView = (MapView)findViewById(R.id.mapView);
            Intent intent = getIntent();
    		Bundle extras =intent.getExtras();
    		if (extras != null){
    			this.myList = (ArrayList<Place>) extras.getSerializable("myList");
    			 lt=Double.parseDouble(intent.getStringExtra("latitude"));
    			 lg=Double.parseDouble(intent.getStringExtra("longitude"));
    			 pos=Integer.parseInt(intent.getStringExtra("id"));
            //Example data
            double latitudeFrom = lt;
            double longitudeFrom = lg;
            double latitudeTo = myList.get(pos).getLatitude();
            double longitudeTo = myList.get(pos).getLongitude();
     
            srcGeoPoint = 
            	new GeoPoint((int)(latitudeFrom * 1E6), (int)(longitudeFrom * 1E6));
             destGeoPoint = 
            	new GeoPoint((int)(latitudeTo * 1E6), (int)(longitudeTo * 1E6));
     
          new AsyncTask <Void, Void, Void>(){
        	  @Override
     
        	  protected  Void doInBackground(Void... params) {
        			// TODO Auto-generated method stub
        			String strUrl = "http://maps.google.com/maps?";
        			//From
        			strUrl += "saddr=" +
        				   (srcGeoPoint.getLatitudeE6()/1.0E6) + 
        				   "," +
        				   (srcGeoPoint.getLongitudeE6()/1.0E6);
        			//To
        			strUrl += "&daddr=" +
        				   (destGeoPoint.getLatitudeE6()/1.0E6) + 
        				   "," + 
        				   (destGeoPoint.getLongitudeE6()/1.0E6);
        			//Walk attribute (for walk path)
        			strUrl += "&dirflg=w";
        			//File format
        			strUrl += "&output=kml";
     
        	    	try {
        	    		//Parse KML
        				URL url = new URL(strUrl.toString());
     
        				SAXParserFactory saxFactory = SAXParserFactory.newInstance();
        				SAXParser parser = saxFactory.newSAXParser();
        				XMLReader reader = parser.getXMLReader();
     
        				KMLHandler kmlHandler = new KMLHandler();
        				reader.setContentHandler(kmlHandler);
     
        				InputSource inputSource = new InputSource(url.openStream());
        				reader.parse(inputSource);
     
        				String path = kmlHandler.getPathCoordinates();
        				//Draw path
        				if(path != null) {
        					RouteOverlay routeOverlay = new RouteOverlay();
     
        					String pairs[] = path.split(" ");
     
        					for (String pair : pairs) {
        						String coordinates[] = pair.split(",");
        						GeoPoint geoPoint = new GeoPoint(
        								(int) (Double.parseDouble(coordinates[1]) * 1E6),
        								(int) (Double.parseDouble(coordinates[0]) * 1E6));
        						routeOverlay.addGeoPoint(geoPoint);
        					}
     
        					mapView.getOverlays().add(routeOverlay);
        				}
     
        			} catch (Exception e) {
        				Log.w("RoutePath", e.toString());
        			}
     
     
     
     
     
     
            mapView.getController().animateTo(srcGeoPoint);
            mapView.getController().setZoom(15);
        	return null;
    		};
     
     
     
    		}.execute();
     
     
    }
    }
    }
    J'obtient ce nouveau erreur dans le logcat:

    org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 484: mismatched tag

    Si quelqu'un avez des idées pour corriger cette erreur , aidez moi et merci d'avance.

Discussions similaires

  1. Affichage itinéraire et marker en fonction d'une recherche
    Par nhl57 dans le forum SIG : Système d'information Géographique
    Réponses: 2
    Dernier message: 27/03/2013, 19h48
  2. [Google Maps] Affichage de plusieurs itinéraires google map
    Par BOUMAILI dans le forum APIs Google
    Réponses: 2
    Dernier message: 03/07/2012, 22h39
  3. [Google Maps] Affichage de plusieurs itinéraires
    Par Kentin64 dans le forum APIs Google
    Réponses: 4
    Dernier message: 20/06/2012, 20h40
  4. Calcul est affichage d' itinéraire dans une carte google Maps sur Android
    Par developpCathy dans le forum API standards et tierces
    Réponses: 1
    Dernier message: 09/05/2012, 00h27
  5. Affichage en passant par un buffer...
    Par Sirotilc dans le forum MFC
    Réponses: 5
    Dernier message: 27/05/2002, 21h00

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo