Draw path on google map based on lat lang

前端 未结 4 852
失恋的感觉
失恋的感觉 2020-12-16 16:14

i want to draw path on google map.

Basically what i am tracking user locaion after specfic time interval. when user reach to some destination then i need to draw the

4条回答
  •  执念已碎
    2020-12-16 17:07

    The problem is not on your drawing function but on the method you are using to get the points of your path using the received location.

    You need to take into account two factors:

    • First of all, the accuracy of the received location. You can get the accuracy using the Location.getAccuracy() method (documentation). The accuracy is measured in meters, so the lower the better.
    • On the other hand, you may want to add a new location to your polyline only if your new location is farther than a given distance to your last added location.

    An example combining both considerations:

    private static final float MINIMUM_ACCURACY = 10; // If the accuracy of the measurement is worse than 10 meters, we will not take the location into account
    private static final float MINIMUM_DISTANCE_BETWEEN_POINTS = 20; // If the user hasn't moved at least 20 meters, we will not take the location into account
    private Location lastLocationloc;
    
    // ...
    
    public void onLocationChanged(Location mylocation) {
        if (mylocation.getAccuracy() < MINIMUM_ACCURACY) {
            if (lastLocationloc == null || lastLocationloc.distanceTo(mylocation) > MINIMUM_DISTANCE_BETWEEN_POINTS) {
                // Add the new location to your polyline
    
                lastLocationloc = mylocation;
            }
        }
    }
    

提交回复
热议问题