How to Highlight a specified route on Google Maps v2 Android? -


I am using the Google Directions API in my app to recover the path between two places which are completely Now I just need to list the roads and guidelines in the list view:

List view

How can I do this?

Use this code Hope it can help you!

Now on the map, a specified route on ABC is highlighted (screenshot below). highlight the specified route

  Increases the public class polymorph activity (progressivity) pdialog; GoogleMap map, list of & lt; LatLng & gt; polyz; JSONArray array; static final Letlng Dublin = new Lie Long (53.344103999999990000, -6.2674 93699999932000); @SuppressLint ( "NewApi") saved preserved create null (Bundle Instansstet) {Suprknkret (saved Instensstet); setContentView (R.layout.map_layout); Map = ((MapFragment) getFragmentManager (). FindFragmentById (R.id.map)) .getMap (); Map .moveCamera (CameraUpdateFactory.newLatLongZoom (DUBLIN, 15)); Map.animateCamera (CameraUpdateFactory.zoomTo (10), 2000, NULL); new GetDirection (). execute ();} class GetDirection AsyncTask and lt; string, string, string & Gt; {Preferred PreExecute at Safe Over Zero (@Override) {super.onPreExecute (); PDialog = New Progress Diigo (PolyMap.This); PDialog.setMessage ("Loading the route, please wait ..."); pDialog .setIndeterminate (wrong); PDialog.setCancelable (wrong); PDialog.show (); } Protected string doInBackground (string ... args) {intent I = getIntent (); String start position = i.getStringExtra ("startLoc"); String end space = i.getStringExtra ("endLoc"); StartLocation = startLocation.replace ("", "+"); EndLocation = endLocation.replace ("", "+") ;; String string = "http://maps.googleapis.com/maps/api/directions/json?origin=" + startLocation + ", + dubulin and destination =" + end space + ", + doubulin and sensor = false"; StringBilder Response = New StringBuilder (); {URL url = Try new URL (string url); HttpURL connection httpconn = (HttpURLConnection) url .openConnection (); If (httpconn.getResponseCode () == HttpURLConnection.HTTP_OK) {BufferedReader input = new BufferedReader (New InputStreamReader (httpconn.getInputStream ()), 8192); String string = null; While ((strLine = input.readLine ()) = null) {response.append (strLine); } Input.close (); } String jsonOutput = response.toString (); JSONObject jsonObject = New JSONObject (jsonOutput); // All routes in the route array include JSONArray routesArray = jsonObject.getJSONArray ("route"); // First path JSONObject path = routes Array.getJSONObject (0); JSONObject poly = route.getJSONObject ("overview_polyline"); String Polyline = PolyGetString ("Points"); Polyis = decodpoli (polyline); } Hold (exception e) {} return tap; } Protected void onPostExecute (string file_url) {for (int i = 0; i & lt; polyz.size () - 1; i ++) {letting src = polyz.get (i); LatLng dest = polyz.get (i + 1); Polyline line = Map.adpolilain (new polyline option () .ad (new slots long (Sarsi. Latetid, SRC Langtid), new slots Long (Distklitidet, Dest Laँgtrad)). Wide (2). Color (Rngkaridi ) .geodesic (true)); } PDialog.dismiss (); }} / * Method to decode polyline points / private list & lt; LatLng & gt; DecodePoly (string-encoded) {list & lt; LatLng & gt; Poly = new arrelisted & lt; LatLng & gt; (); Int index = 0, lenon = encoded.lam (); Int lat = 0, lng = 0; While (index & lt; len) {int b, shift = 0, result = 0; Do {b = encoded. Chart (index ++) - 63; Results | = (B & 0x1f) & lt; & Lt; Shift; Change + = 5; } While (b> = 0x20); Int dlat = ((Results and 1)! = 0? ~ (Results >> 1): (Results >> 1)); Latitude + = DLAT; Shift = 0; Result = 0; Do {b = encoded. Chart (index ++) - 63; Results | = (B & 0x1f) & lt; & Lt; Shift; Change + = 5; } While (b> = 0x20); Int dlng = ((Results and 1)! = 0? ~ (Results & gt; & gt; 1): (Results & gt; & gt; 1); Lng + = dlng; LatLng p = new wave long (((double latitude / 1e5)), (((double) LNG / 1E5)); Poly.add (p); } Return shift; }}    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -