如果我在我的 MapActivity 中添加了大约 100 个地理点,并且我只想显示距离我当前位置大约 1000 米的地理点,有什么办法吗?其他的应该在 map 上不可见。
有什么建议吗?
最佳答案
好的,这是例子。您可以继承 Overlay 类并覆盖 draw 方法。每当 Overlay 失效时,您应该检查您的点是否在距您所在位置 1000 米以内。当然,您应该知道您在覆盖类中的位置。流动就是例子:
public class MyMapOverlay extends Overlay {
Bitmap bmp;
Context context;
public MyMapOverlay()
{
bmp = BitmapFactory.decodeResource(MyApplication.getContext().getResources(), R.drawable.myplace);
}
@Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when)
{
super.draw(canvas, mapView, shadow);
Point screenPts = new Point();
for(int i = 0;i<points.size(); i++)
{
GeoPoint point = points.get(i);
Location locationA = new Location("point " + String.valueOf(i));
locationA.setLatitude(point.getLatitudeE6());
locationA.setLongitude(point.getLongitudeE6());
float distance = myLocation.distanceTo(locationA);
if(distance < 1000.0)
{
mapView.getProjection().toPixels(p, screenPts);
canvas.drawBitmap(bmp, screenPts.x-bmp.getWidth()/2, screenPts.y-bmp.getHeight(), null);
}
}
return true;
}
关于Android 谷歌地图显示最接近当前位置的地理点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12795857/