android如何检查Point是否在我的屏幕内

时间:2012-09-16 20:15:30

标签: android google-maps map-projections

我得到一个Point对象抛出我的MapView Projectiion对象。

我有一个叠加列表,我想检查每个叠加是否在我当前的屏幕内(诅咒取决于缩放级别)。

我无法找到检查某个点是否在屏幕内的方法。

我所发现的是,当我从投影中记录点数时,屏幕上没有的点数具有负值..

是否可以说如果Point有一个负值,它就在我的屏幕之外?

1 个答案:

答案 0 :(得分:6)

    GeoPoint yourPoint = null;// w/e point u wanna see is on the screen

    Point newPoint = null; // x/y point

    mapView.getProjection().toPixels(yourPoint, newPoint); //convert to xy Point

    int height = context.getResources().getDisplayMetrics().heightPixels;

    int width = context.getResources().getDisplayMetrics().widthPixels;

    Rect screen = new Rect(0,0,width,height); //rect that represents your Screen

    if(screen.contains(newPoint.x, newPoint.y){
         // your point is on the screen
    }