1

I am developing an android application in this application i want to draw a path on Google maps

When user moves with his device path is draw on map i don't want to draw path between two points

I want that every time when location is update path is drawn on map

If anyone know please help me Thanks

Mahtab
  • 269
  • 3
  • 11

1 Answers1

1

Each and everytime when you get new Latitude and Longitude, just call one user defined method, like, drawTrack(). But before that whatever value you got first time, just store that value in like in previous_lat and previous_long variable. Then, when you got lat-long second time that means your source lat-long is previous_lat and previous_long and latest one is which you have got currently. Then give that 4 vaues to drawTrack() method.

Inside DrawTrack() method,

googleMap.addPolyline(new PolylineOptions().add(new LatLng(Double.parseDouble(YOUR PREVIOUS LATITUDE VALUE), Double.parseDouble(YOUR PREVIOUS LONGITUDE VALUE), new LatLng(Double.parseDouble(YOUR LATEST LATITUDE VALUE), Double.parseDouble(YOUR LATEST LONGITUDE VALUE).width(5)     .color(getResources().getColor(R.color.BLACK)).geodesic(true));
Pratik Dasa
  • 7,439
  • 4
  • 30
  • 44
  • its not working i written this code private void drawTrack(double new_lat, double new_long, double previous_lat, double previous_long) { PolylineOptions options = new PolylineOptions(); options.add(new LatLng(previous_lat, previous_long)); options.add(new LatLng(new_lat, new_long)); options.width(15); options.color(Color.RED); mMap.addPolyline(options); } – Mahtab Jun 23 '14 at 13:48
  • @Mahtab ya then its must be work, check you have some other mistakes, because this code working prefect with me. – Pratik Dasa Jun 24 '14 at 05:12
  • public void onLocationChanged(Location location) { String msg = "Location:" + location.getLatitude() + "," + location.getLongitude(); Toast.makeText(this, msg, Toast.LENGTH_LONG).show(); double new_lat = location.getLatitude(); double new_long = location.getLongitude(); double previous_lat = new_lat; double previous_long = new_long; drawTrack(new_lat, new_long, previous_lat, previous_long); } – Mahtab Jun 24 '14 at 06:22
  • this is my on location changed method please see if any mistake tell me i am ne in android – Mahtab Jun 24 '14 at 06:23
  • odedraram28@gmail.com – Pratik Dasa Jun 24 '14 at 08:47