0

実際の G​​PS 位置を表示するために青い半透明の円を描画しようとしましたが、円が表示されNutiteq's Mapません。

このようなものを表示したい ここに画像の説明を入力

私のコードは次の Circleクラスです

public Circle(MapView mapView, MapPos mapPostPoint, float radius, Paint paintFill, Paint paintStroke) {
        checkRadius(radius);
        this.mapView      = mapView;
        this.mapPostPoint = mapPostPoint;
        this.radius       = radius;
        this.paintFill    = paintFill;
        this.paintStroke  = paintStroke;

        this.gUtils = new GeometricUtils(this.mapView);
}

public synchronized boolean draw(MapPos point, Canvas canvas, float radius, float zoomLevel) {
        if (this.mapPostPoint == null || (this.paintStroke == null && this.paintFill == null)) {
                return false;
        }

        double latitude  = point.x;
        double longitude = point.y;

        MapPos screenPoint = mapView.worldToScreen(point.x, point.y, 0);
        float pixelX = (float) screenPoint.x;
        float pixelY = (float) screenPoint.y;


        float radiusInPixel = (float) gUtils.metersToPixels((double)this.radius, latitude, zoomLevel);

        if (this.paintStroke != null) {
            canvas.drawCircle(pixelX, pixelY, radiusInPixel, this.paintStroke);
        }
        if (this.paintFill != null) {
            canvas.drawCircle(pixelX, pixelY, radiusInPixel, this.paintFill);
        }

        return true;
}

GeometricUtilsクラスを次のように

...
private static final int tileSize = 256;
...

public double resolution(double latitude, float scaleFactor) {
    long mapSize = getMapSize(scaleFactor, tileSize);
    return Math.cos(latitude * (Math.PI / 180)) * earthCircumference / mapSize;
}   

// Here I get how many Pixels I need to represent a distance of "meters"
public double metersToPixels(double meters, double latitude, float zoom) {
    double res = resolution(latitude, zoom);

    return meters / res;

}   


public long getMapSize(float scaleFactor, int tileSize) {
        if (scaleFactor < 1) {
                throw new IllegalArgumentException("scale factor: " + scaleFactor + " should be >= 1 ");
        }
        return (long) (tileSize * (Math.pow(2, scaleFactorToZoomLevel(scaleFactor))));
}


public double scaleFactorToZoomLevel(double scaleFactor) {
       return Math.log(scaleFactor) / Math.log(2);
} 

そしてMyLocationCircle最後の授業

public class MyLocationCircle {

private final   GeometryLayer layer;
private MapView mapView;

private MapPos  circlePos       = new MapPos(0, 0);
private float   circleScale     = 0;
private float   circleRadius    = 1;
private float   projectionScale = 0;
private boolean visible = false;
private Circle  circle;
private Paint   fill            = new Paint();
private Paint   stroke          = new Paint();
private Canvas  canvas          = new Canvas();

public MyLocationCircle(GeometryLayer layer, MapView mapView, double radius) {
    // Initialize Paint
    initializeGraphics();
    //

    this.layer        = layer;
    this.mapView      = mapView;
    this.circleRadius = (float)radius;
    this.circle       = new Circle(this.mapView, this.circlePos, this.circleRadius, this.fill, this.stroke);

}

public void setVisible(boolean visible) {
    this.visible = visible;
}

public void setLocation(Projection proj, Location location) {
    circlePos = new MapPos(location.getLongitude(), location.getLatitude());//proj.fromWgs84(location.getLongitude(), location.getLatitude());

    projectionScale = (float) proj.getBounds().getWidth();
    circleRadius = location.getAccuracy();

}

public void draw(MapPos position) {
    float zoom = mapView.getZoom();
    circle.draw(position, canvas, circleRadius, zoom);      
}

public MapPos getLocation() {
    return circlePos;
}

protected void initializeGraphics() {

    fill.setStyle(Paint.Style.FILL);
    fill.setColor(Color.BLUE);
    fill.setAlpha(60);

    stroke = new Paint();
    stroke.setStrokeWidth(3.0f);        
    stroke.setStyle(Paint.Style.STROKE);
    stroke.setColor(Color.BLUE);

}

}

screenToWorld(...)メソッドMethod で右に反転でき、正しい地理座標を取得できるため、地理座標を画面座標に変換します。では、何が間違っているのでしょうか。

PolygonsLinesMarkers、などを描画できるLabelsので、正しいレイヤーを介してマップにアタッチできますがCanvas、マップ上に単純な円を表示できません。

よろしくお願いします。

4

1 に答える 1