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

Asa*_*evo 1 android google-maps map-projections

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

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

我找不到检查给定点是否在屏幕内的方法.

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

如果一个Point有一个负值,它是否在我的屏幕之外是真的吗?

Jug*_*aut 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
    }
Run Code Online (Sandbox Code Playgroud)