Search code examples
androidgoogle-mapspolygonandroid-gpsgpsd

How to fix this problem Collect coordinates to point polygon


I have problem about my gps and plot polygon

I collect GPS every second from

Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);

and put it to realm database

(So I things do I not good idea)
Maybe should accumulate every 10 meters

image below is result I got

this is result amazing I'm lie my problems

  1. Polygon look alike the PASTA instead of area.

  2. My gps can jump over to another building(GPS is not stable)

help recommend me please.

ArrayList<LatLng> coordList = new ArrayList<LatLng>(); 

      @Cleanup Realm realm = Realm.getDefaultInstance();

        RealmResults<PolygonAreas> PlotPolygon = realm.where(PolygonAreas.class).findAll();

                            if (PlotPolygon.size() > 0) {
                                for (PolygonAreas Polypoint : PlotPolygon) {

                                    coordList.add(new LatLng(Polypoint.getLatitude(), Polypoint.getLongitude()));

                                    try {
                                        Runnable addPolygon = new CellTowerMarkerGoogle.AddPolygon(mMap, new PolygonOptions()
                                                .addAll(coordList).fillColor(0x7F80b370).strokeColor(0x7F80b370)
                                        );
                                        getActivity().runOnUiThread(addPolygon);
                                    } catch (Exception e) {
                                        log.debug("Exception : " + e);
                                    }
                                }
                            }


         public  static class AddPolygon implements Runnable{
                private  GoogleMap map;
                private PolygonOptions options;

                public  AddPolygon(GoogleMap map,PolygonOptions options){
                    this.map = map;
                    this.options = options;

                }
                @Override
                public void run() { map.addPolygon(options);}
            }

Solution

  • I found problem Because my logic incorrect variable addPolygon every back again it's create new Object polygon(.addAll) It causes the creation of overloaded objects.

    How can I fix it? I have to destroy the polygon object and recreate it every time. The value will be updated all the time. I have to destroy and create new polygons every time to update.