현재 볼 수있는 지역에 Geopoint가 표시되는지 어떻게 결정할 수 있습니까?

StackOverflow https://stackoverflow.com/questions/2248510

  •  20-09-2019
  •  | 
  •  

문제

내 Android 앱에 MapView Control이 있다고 가정 해 봅시다. 랜드 마크가 특정 위도와 경도에 존재한다는 것을 알고 있다면 해당 랜드 마크가 현재 사용자 화면에서 볼 수 있는지 어떻게 확인할 수 있습니까? 가시 영역의 왼쪽 상단 및 하단 오른쪽 모서리의 좌표를 얻는 방법이 있습니까?

도움이 되었습니까?

해결책

Geopoint를 가리키고 상자 (0, 화면 너비)인지 확인할 수 있습니다 (0, 화면 높이).

보다: https://developer.android.com/reference/com/google/android/gms/maps/projection.html

다른 팁

이와 같은 일이 트릭을 할 것입니다.

private boolean isCurrentLocationVisible()
    {
        Rect currentMapBoundsRect = new Rect();
        Point currentDevicePosition = new Point();
        GeoPoint deviceLocation = new GeoPoint((int) (bestCurrentLocation.getLatitude() * 1000000.0), (int) (bestCurrentLocation.getLongitude() * 1000000.0));

        mapView.getProjection().toPixels(deviceLocation, currentDevicePosition);
        mapView.getDrawingRect(currentMapBoundsRect);

        return currentMapBoundsRect.contains(currentDevicePosition.x, currentDevicePosition.y);

    }

팁에 가입 여기, 여기 그리고 여기:

내 custommapview의 전체 코드는 다음과 같습니다.

package net.alouw.alouwCheckin.ui.map;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Pair;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;

/**
 * @author Felipe Micaroni Lalli (micaroni@gmail.com)
 */
public class CustomMapView extends MapView {  
    public CustomMapView(Context context, String s) {
        super(context, s);
    }

    public CustomMapView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
    }

    public CustomMapView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
    }

    /**
     *
     * @return a Pair of two pairs with: top right corner (lat, lon), bottom left corner (lat, lon)
     */
    public Pair<Pair<Double, Double>, Pair<Double, Double>> getMapCorners() {
        GeoPoint center = getMapCenter();
        int latitudeSpan = getLatitudeSpan();
        int longtitudeSpan = getLongitudeSpan();

        double topRightLat = (center.getLatitudeE6() + (latitudeSpan / 2.0d)) / 1.0E6;
        double topRightLon = (center.getLongitudeE6() + (longtitudeSpan / 2.0d)) / 1.0E6;

        double bottomLeftLat = (center.getLatitudeE6() - (latitudeSpan / 2.0d)) / 1.0E6;
        double bottomLeftLon = (center.getLongitudeE6() - (longtitudeSpan / 2.0d)) / 1.0E6;

        return new Pair<Pair<Double, Double>, Pair<Double, Double>>(
                new Pair<Double, Double>(topRightLat, topRightLon),
                new Pair<Double, Double>(bottomLeftLat, bottomLeftLon));
    }
}

OK 이제 간단한 작업 솔루션을 찾는 데 시간이 걸렸으므로 여기에 저를 위해 여기에 게시 할 것입니다.) MapView의 하위 클래스에서 다음을 사용하십시오.

GeoPoint topLeft = this.getProjection().fromPixels(0, 0);
GeoPoint bottomRight = this.getProjection().fromPixels(getWidth(),getHeight());

그게 전부, 그러면 당신은

topLeft.getLatitudeE6() / 1E6
topLeft.getLongitudeE6() / 1E6

그리고

bottomRight.getLatitudeE6() / 1E6
bottomRight.getLongitudeE6() / 1E6
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top