Scale coordinates on radar

2019-09-11 07:09发布

问题:

I'm currently developing an radar for android. (Following this tutorial: http://www.androidph.com/2009/02/app-10-beer-radar.html )

I'm getting all users within a range of 5KM around my current location from the server after that I draw in my customview like this:

float xU = (float)(userLocation.getLongitude() + getWidth() / 2 - currentLong);
float yU = (float)(getHeight() / 2 - userLocation.getLatitude() + currentLat);
canvas.drawBitmap(bmpUser,xU,yU,radarPaint);

Now my problem is, that I need to scale the the points / coordinates I draw on the radar, because all users within a distance below 5KM will be drawn like only 2-3 Pixel away from the center. How would I manage to do that?

回答1:

This is one way to do it. All you need to do is to set the value of the "scale" variable to the required value;

float scale = 3.0f; //set this to any number to change the drawing scale

float xU = (float)(getWidth() / 2 + (userLocation.getLongitude() - currentLong) * scale);
float yU = (float)(getHeight() / 2 - (userLocation.getLatitude() - currentLat) * scale);
canvas.drawBitmap(bmpUser,xU,yU,radarPaint);