【问题标题】:android how to check if a Point is inside my screenandroid如何检查一个点是否在我的屏幕内
【发布时间】:2012-09-16 20:15:29
【问题描述】:

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

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

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

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

如果一个点的值为负值,它在我的屏幕之外是真的吗?

【问题讨论】:

    标签: android google-maps map-projections


    【解决方案1】:
        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
        }
    

    【讨论】:

    • 不知道你写错了,还是改了一些东西,但是Rect构造函数中的height和width错误(0,0,width,height)。
    猜你喜欢
    • 2014-12-15
    • 1970-01-01
    • 1970-01-01
    • 2012-02-14
    • 2013-07-20
    • 2012-11-26
    • 1970-01-01
    • 1970-01-01
    • 2012-02-12
    相关资源
    最近更新 更多