Android - Remove the straight line while displaying multiple routes on a map -


enter image description herein application, display of map , multiple routes between source , destination done using google mapv2 api. problem is, while displaying multiple routes on map, 1 straight comes along correct routes. want rid of straight line between source , destination. trying find way past 2 days. please guide me.

displaymap.java

polylineoptions rectline = null;             if(result.equalsignorecase("exception caught")){                 toast.maketext(getapplicationcontext(), "invalid values", toast.length_long).show();             }             else{             if (weakref.get() != null && ! weakref.get().isfinishing()){          //  if(response.equalsignorecase("success")){                 arraylist<latlng> directionpoint = v2getroutedirection.getdirection(document);                 int duration = v2getroutedirection.getdurationvalue(document);                 log.e("traffic durationtime",""+duration);                 int trfficcleartime = v2getroutedirection.getdistancevalue(document);                 log.e("traffic time", ""+trfficcleartime);                  markeropition.position(myposition).icon(bitmapdescriptorfactory                         .defaultmarker(bitmapdescriptorfactory.hue_red))                           .flat(true);                 markeropition2.position(myposition2).icon(bitmapdescriptorfactory                              .defaultmarker(bitmapdescriptorfactory.hue_azure))                              .flat(true);                 markeropition.draggable(true);                 markeropition2.draggable(true);                 googlemap.movecamera(cameraupdatefactory.newlatlngzoom(myposition,10));                 googlemap.addmarker(markeropition);                 googlemap.addmarker(markeropition2);                        rectline = new polylineoptions().width(5).color(color.red);                      (int = 0; < directionpoint.size(); i++) {                          rectline.add(directionpoint.get(i));                      }                 googlemap.addpolyline(rectline);                     showdirection.settext("");                        // convert unicode utf-8                     arraylist<string> dir = v2getroutedirection.getdirectionpanel(document);                     if(dir.size()!=0){                     for(int i=0;i<dir.size();i++){                      string godirections=dir.get(i).replaceall("\\<.*?>","");                      showdirection.append(godirections+"\n");                      log.e("size", ""+dir.size());                        log.e("panel", godirections);                     }                     }                     else{                         toast.maketext(getapplicationcontext(), "no value", toast.length_long).show();                     }                      string alter = v2getroutedirection.getalternativeroutes(document);                      log.e("alter", alter);                      }             } 

gmpv2directions.java(for drawing routes)

public class gmapv2direction {      public final static string mode_driving = "driving";     public final static string mode_walking = "walking";       public gmapv2direction() { }       public document getdocument(latlng start, latlng end, string mode) {         string url = "http://maps.googleapis.com/maps/api/directions/xml?"                 + "origin=" + start.latitude + "," + start.longitude                  + "&destination=" + end.latitude + "," + end.longitude                 + "&sensor=false&units=metric&mode=driving&alternatives=true";           try {             httpclient httpclient = new defaulthttpclient();             httpcontext localcontext = new basichttpcontext();             httppost httppost = new httppost(url);             httpresponse response = httpclient.execute(httppost, localcontext);             inputstream in = response.getentity().getcontent();             documentbuilder builder = documentbuilderfactory.newinstance().newdocumentbuilder();             document doc = builder.parse(in);             return doc;         } catch (exception e) {             e.printstacktrace();         }         return null;     }       public string getdurationtext (document doc) {          nodelist nl1 = doc.getelementsbytagname("duration");           node node1 = nl1.item(nl1.getlength() - 1);           nodelist nl2 = node1.getchildnodes();           node node2 = nl2.item(getnodeindex(nl2, "text"));           log.i("durationtext", node2.gettextcontent());           return node2.gettextcontent();     }       public int getdurationvalue (document doc) {         nodelist nl1 = doc.getelementsbytagname("duration");         node node1 = nl1.item(nl1.getlength() - 1);         nodelist nl2 = node1.getchildnodes();         node node2 = nl2.item(getnodeindex(nl2, "value"));         log.i("durationvalue", node2.gettextcontent());         return integer.parseint(node2.gettextcontent());     }       public string getdistancetext (document doc) {         nodelist nl1 = doc.getelementsbytagname("distance");         node node1 = nl1.item(0);         nodelist nl2 = node1.getchildnodes();         node node2 = nl2.item(getnodeindex(nl2, "text"));         log.i("distancetext", node2.gettextcontent());         return node2.gettextcontent();     }       public int getdistancevalue (document doc) {         nodelist nl1 = doc.getelementsbytagname("distance");         node node1 = nl1.item(0);         nodelist nl2 = node1.getchildnodes();         node node2 = nl2.item(getnodeindex(nl2, "value"));         log.i("distancevalue", node2.gettextcontent());         return integer.parseint(node2.gettextcontent());     }       public string getstartaddress (document doc) {         nodelist nl1 = doc.getelementsbytagname("start_address");         node node1 = nl1.item(0);         log.i("startaddress", node1.gettextcontent());         return node1.gettextcontent();     }       public string getendaddress (document doc) {         nodelist nl1 = doc.getelementsbytagname("end_address");         node node1 = nl1.item(0);         log.i("startaddress", node1.gettextcontent());         return node1.gettextcontent();     }     public arraylist<string> getdirectionpanel(document doc){         node node1 = null;         arraylist<string> arry = new arraylist<string>();         nodelist nl1 = doc.getelementsbytagname("html_instructions");          for(int = 0;i<nl1.getlength();i++){         node1 = nl1.item(i);         arry.add(node1.gettextcontent());          log.i("direction panel", node1.gettextcontent());          }         return arry;     }    public string getalternativeroutes(document doc){         nodelist nl1;       node  firstnode=null;       node first = null;       nodelist nodelist = doc.getelementsbytagname("route");       if(nodelist.getlength()>0){           for(int j=0;j<nodelist.getlength();j++){                node node1 = nodelist.item(j);               nl1 = node1.getchildnodes();               first = nl1.item(getnodeindex(nl1, "summary"));               log.e("first", first.gettextcontent());           }           }       return first.gettextcontent();    }       public string getcopyrights (document doc) {         nodelist nl1 = doc.getelementsbytagname("copyrights");         node node1 = nl1.item(0);         log.i("copyrights", node1.gettextcontent());         return node1.gettextcontent();     }       public arraylist<latlng> getdirection (document doc) {         nodelist nl1, nl2, nl3;         arraylist<latlng> listgeopoints = new arraylist<latlng>();         nl1 = doc.getelementsbytagname("step");         if (nl1.getlength() > 0) {             (int = 0; < nl1.getlength(); i++) {                 node node1 = nl1.item(i);                 nl2 = node1.getchildnodes();                   node locationnode = nl2.item(getnodeindex(nl2, "start_location"));                 nl3 = locationnode.getchildnodes();                 node latnode = nl3.item(getnodeindex(nl3, "lat"));                 double lat = double.parsedouble(latnode.gettextcontent());                 node lngnode = nl3.item(getnodeindex(nl3, "lng"));                 double lng = double.parsedouble(lngnode.gettextcontent());                 listgeopoints.add(new latlng(lat, lng));                   locationnode = nl2.item(getnodeindex(nl2, "polyline"));                 nl3 = locationnode.getchildnodes();                 latnode = nl3.item(getnodeindex(nl3, "points"));                arraylist<latlng> arr = decodepoly(latnode.gettextcontent());                 for(int j = 0  ; j < arr.size() ; j++) {                     listgeopoints.add(new latlng(arr.get(j).latitude, arr.get(j).longitude));                   }                     locationnode = nl2.item(getnodeindex(nl2, "end_location"));                 nl3 = locationnode.getchildnodes();                 latnode = nl3.item(getnodeindex(nl3, "lat"));                 lat = double.parsedouble(latnode.gettextcontent());                 lngnode = nl3.item(getnodeindex(nl3, "lng"));                 lng = double.parsedouble(lngnode.gettextcontent());                 listgeopoints.add(new latlng(lat, lng));                  locationnode = nl2.item(getnodeindex(nl2, "start_location"));             }         }           return listgeopoints;     }       private int getnodeindex(nodelist nl, string nodename) {         for(int = 0 ; < nl.getlength() ; i++) {             if(nl.item(i).getnodename().equals(nodename))                 return i;         }         return -1;     }       private arraylist<latlng> decodepoly(string encoded) {         arraylist<latlng> poly = new arraylist<latlng>();         int index = 0, len = encoded.length();         int lat = 0, lng = 0;         while (index < len) {             int b, shift = 0, result = 0;             {                 b = encoded.charat(index++) - 63;                 result |= (b & 0x1f) << shift;                 shift += 5;             } while (b >= 0x20);             int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));             lat += dlat;             shift = 0;             result = 0;             {                 b = encoded.charat(index++) - 63;                 result |= (b & 0x1f) << shift;                 shift += 5;             } while (b >= 0x20);             int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));             lng += dlng;               latlng position = new latlng((double) lat / 1e5, (double) lng / 1e5);             poly.add(position);         }         return poly;     }   } 

thanks in advance!

fallow how draw free hand polygon in google map v2 in android?

there's deep discussion same on there ...

kindly check out list part how things happened on there.

your logic can check source , destination point regularly. after need create common method draw path on map.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -