2012-09-16 2 views
1

Point 객체를 가져 와서 MapView Projectiion 객체를 던집니다.android 내 화면에 Point가 있는지 확인하는 방법

나는 오버레이 목록을 가지고 있는데, 각 오버레이가 현재 화면 안에 있는지 (저주인지는 줌 레벨에 따라 다름) 확인하고 싶습니다.

주어진 지점이 화면 안에 있는지 확인할 방법을 찾지 못했습니다. 내가 발견 했는가

이 사실 말을하는 것입니다 .. 내가 프로젝션에서 포인트를 로깅있을 때, 포인트가 음의 값이 화면에없는 that're이다 점이있는 경우 그 음수 값으로 내 화면 밖에 있습니까?

답변

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 
    } 
+1

Rect 생성자 (0,0, width, height)에서 실수가 있거나 변경된 것이 있지만 높이와 너비가 잘못되었습니다. – Trick

관련 문제