Draw a polyline in Android google maps as the user move -


hy, i'm newbie in android, , i've learned android google maps. i'd tracking user movement , draw polyline path in android google maps in real time, can me example? can location chage interval still don't know how apply polyline , keep data latlng array.

you need add this/related g.play services virsion line in gradle in case haven't.

compile 'com.google.android.gms:play-services-maps:8.4.0' 

as official doc says , use code.

googlemap map;  // ... map.  // add thin red line london new york.  polyline line = map.addpolyline(new polylineoptions()      .add(new latlng(51.5, -0.1), new latlng(40.7, -74.0))      .width(5)      .color(color.red)); 

note: methods modify polyline must called on main thread if not, illegalstateexception thrown @ run-time.

for sake know can find code here small logic

  1. keep start , end position latlng variables (startlatlng ,endlatlng)
  2. as can see in example cannot send hard coded values,pass real values take location when user moves or may after time period
  3. write logic : startlatlng = new latlng data got when user move / after time period;
  4. only first time startlatlng = endlatlng (use if condition boolian , change value after gets called )
  5. call method draw poly-line line (startlatlng , endlatlng)
  6. endlatlng = startlatlng (see after call draw method set start value end value)

note

if it's confusing use real values , try understand explained. first time both same. darws dot because both in same spot.(i guess) startlatlng & endlatlng both have first same value.

second time new location comes startlatlng changes.then cannot go boolean if method because it's first time.

now call method draw line (new startlatlng , old endlatlng). after call draw method, endlatlng gets new startlatlng value.

but next time when full logic gets called new data again new data assigns startlatlng.

so in way can draw line between startlatlng (new possition) endlatlng (oldpossition).


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -