在雷达上测量坐标 [英] Scale coordinates on radar
问题描述
我将我所在位置附近5KM范围内的所有用户从服务器之后,我在我的自定义视图中绘制像这样:
pre $ float $(float)(userLocation.getLongitude()+ getWidth( )/ 2 - currentLong);
float yU =(float)(getHeight()/ 2 - userLocation.getLatitude()+ currentLat);
canvas.drawBitmap(bmpUser,xU,yU,radarPaint);
现在我的问题是,我需要缩放绘制在雷达上的点/坐标,因为距离5KM以内的所有用户都将被绘制为仅距离中心2-3像素。我将如何做到这一点?
这是一种方法。您只需将scale变量的值设置为所需的值;
float scale = 3.0f ; //设置为任意数字来改变绘图比例
float xU =(float)(getWidth()/ 2 +(userLocation.getLongitude() - currentLong)* scale);
float yU =(float)(getHeight()/ 2 - (userLocation.getLatitude() - currentLat)* scale);
canvas.drawBitmap(bmpUser,xU,yU,radarPaint);
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?
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);
这篇关于在雷达上测量坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!