PDA

View Full Version : Android: SKCircle - wrong radius



kimyll
18.03.2015, 17:35
Function onCurrentPositionUpdate callback gives me a new coordinate. I use that coordinate to create another coordinate whose longitude is offset by 0.1. Next i measure a distance (5528.2044418697205) to that coordinate and create a SKCircle whose center is set to be the offset coordinate. Finally I set a radius of the circle to be the measured distance.

I am expecting to see a circle, which pretty much touches my location on the map. However a contour of the circle is far away. Maybe a kilometer or more.

According to docs:

getAirDistance: "The distance will be delivered in meter considering that the earth is a sphere with a predefined radius."
SKCircle "Sets the radius of the circle in meters."

So the problem is not related to mile/kilometers conversion.

Is this a bug or am I missing something?



@Override
public void onCurrentPositionUpdate(SKPosition currentPosition) {
double lat = currentPosition.getCoordinate().getLatitude();
double lon = currentPosition.getCoordinate().getLongitude();
SKCoordinate newcoord = new SKCoordinate(lon-0.1, lat);
double distance = SKComputingDistance.getAirDistance(lon, lat, newcoord.getLongitude(), newcoord.getLatitude());

if(firstupdate){
final SKCircle cc = new SKCircle();
cc.setCircleCenter(newcoord);
cc.setRadius((float) distance);
cc.setOutlineColor(MyApplication.getColor(Color.BL ACK));
cc.setColor(MyApplication.getColor(Color.GREEN));
cc.setIdentifier(1001);
float radius = cc.getRadius();
Log.i(getClass().getSimpleName(), "Radius = "+radius);

final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
mapView.addCircle(cc);
}
}, 2000);

firstupdate = false;
}
MyApplication.getInstance().setCurrentPosition(cur rentPosition);
mapView.reportNewGPSPosition(MyApplication.getInst ance().getCurrentPosition());
mapView.centerMapOnCurrentPositionSmooth(SKMapSurf aceView.DEFAULT_ZOOM_LEVEL, 500);
}

Adela_Silvia
20.03.2015, 10:46
Thanks kymill- we'll investigate this and get back to you asap

dandronic
26.03.2015, 14:45
We've tested the posted code and it seems SKComputingDistance.getAirDistance is not very accurate with big distances as we could reproduce the same behaviour.

If we modified newcord to be closer e.g. SKCoordinate newcoord = new SKCoordinate(lon-0.002, lat); there is no gap. Would modifying the distance between the coordinates work in your scenario?

Please also take into consideration that onCurrentPositionUpdate is very often called and will be slight variations of the current position even if standing still so it might be difficult to have always no gap between the circle and the CCP (you might consider only running your algorithm on a "significant" position change).