10

Androidアプリにマップビューコントロールがあるとします。ランドマークが特定の緯度と経度に存在することがわかっている場合、そのランドマークが現在ユーザーの画面に表示されているかどうかを確認するにはどうすればよいですか?表示領域の左上隅と右下隅の座標を取得する方法はありますか?

4

4 に答える 4

6

このような何かがトリックを行います。

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);

    }
于 2011-02-12T07:49:31.380 に答える
5

GeoPointをPointに投影し、それがボックス(0、画面の幅)x(0、画面の高さ)であるかどうかを確認できます。

参照:https ://developer.android.com/reference/com/google/android/gms/maps/Projection.html

于 2010-02-11T23:19:31.117 に答える
1

ここここここでヒントに参加する:

これが私の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));
    }
}
于 2012-12-02T22:50:48.473 に答える
-1

簡単な解決策を見つけるのに少し時間がかかったので、ここに投稿します;)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
于 2012-09-21T16:06:21.743 に答える