I am drawing heart as a polyline on Google Map depends on radius(1 - 100 meter). Once heart is drawn, user needs to walk on that heart border and need to finish from starting to end (Walking start from bottom then left then right and then bottom again).
I am able to draw heart and I am getting 360 points(latlng). Here is my code which will draw heart and image.
private void initPath() {
path = new PolylineOptions();
path.color(ContextCompat.getColor(mActivity,R.color.heart_green));
path.width(25);
// offset to bottom
double offsetY = getY(Math.toRadians(180));
for (int angle = 0; angle <= 360; angle++) {
double t = Math.toRadians(angle);
double x = getX(t);
double y = getY(t) - offsetY;
//Log.d(TAG, "angle = " + angle + "(x = " + x + ",y= " + y + ")");
//convert x,y to lat lng
LatLng latLng = getLatLng(x, y, center);
path.add(latLng);
heart360Points.add(latLng);
}
}
private double getX(double t) {
return radius * 16 * Math.sin(t) * Math.sin(t) * Math.sin(t) / HEART_RATIO;
}
private double getY(double t) {
return radius * (13 * Math.cos(t) - 5 * Math.cos(2 * t) - 2 * Math.cos(3 * t) - Math.cos(4 * t)) / HEART_RATIO;
}
private LatLng getLatLng(double dx, double dy, LatLng centerHeart) {
return new LatLng(centerHeart.latitude + Math.toDegrees(dy / EARTH_RADIUS),
centerHeart.longitude + Math.toDegrees(dx / EARTH_RADIUS) / Math.cos(Math.toRadians(centerHeart.latitude)));
}
But whenever I tried to walk on heart border then GPS location are too much fluctuating so I am never able to complete walking on heart. I am currently requesting location every second.
Here is my location code.
private static final long FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS = 2000 ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.love_lead_perform);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
mApiClient = new GoogleApiClient.Builder(this)
.addApi(ActivityRecognition.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mApiClient.connect();
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
mSettingsClient = LocationServices.getSettingsClient(this);
createLocationCallback();
createLocationRequest();
createLocationSettingsRequest();
}
private void createLocationSettingsRequest() {
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
builder.addLocationRequest(mLocationRequest);
mLocationSettingsRequest = builder.build();
}
private void createLocationRequest() {
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);
mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}
I don't understand why GPS location is fluctuating too much. I am getting different GPS location even I am standing.
How can i get accurate GPS location?