2014-08-11 2 views
1

Я пытаюсь нарисовать синий полупрозрачный круг, чтобы показать свое фактическое положение GPS на Nutiteq's Map, но он не показывает круг.Я не могу нарисовать свою текущую позицию на карте Нутитек

я хочу показать что-то вроде этого enter image description here

Моего кода следующего 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(...) и я получаю правильные координаты географические, так, , что я делаю не так?

Я могу нарисовать Polygons, Lines, Markers, Labels, и т.д., так что я могу приложить к карте с помощью правильных слоев, но я не могу отобразить простой Canvas круг на карте.

Я благодарю вас за помощь.

ответ

2

Ваш образец кода пропускает многие важные части. Как вы используете свой холст, как он добавляется в макет и как он относится к MapView? Что вызывает circle.draw?

Nutiteq wiki имеет GPS circle sample, вы проверили это? Это добавляет объект Polygon для сопоставления и манипулирует этим с использованием координат карты, поэтому вам не нужно ничего знать о координатах экрана, все это обрабатывается с помощью Nutiteq Maps SDK.

+0

Привет, Яак, я не хотел занимать столько места. Я знаю ваш пример, но я хочу нарисовать круг как «GoogleMaps», потому что я использовал ваш «MyLocationCircle», где вы рисуете растущий «n-side Polygon» как растущий «круг». Мой класс «Circle» находится выше, прямо под картинкой. Я правильно называю свой объект Canvas в этом классе ('Circle'). Я попытался добавить круг как «расширение» «Геометрии» к моему «GeometryLayer» и без расширения класса «Круг», но без успеха. –

+0

Думаю, было бы лучше спросить вас, может ли Nutiteq рисовать круг с вызовом 'canvas.drawCircle (...)'. Если да, то где. Спасибо –

+0

Jaak, я действительно разработал прототип android под 'nutiteq' и хотел отобразить идеальный круг, например' GoogleMaps'. Я просто хотел знать, как я могу самостоятельно рисовать круг через холст, но я не могу так долго «инвестировать» в это. Я сделаю это так, как я это сделал, поэтому, как 'n вершин Polygon', как в' HelloMap3d'. Надеюсь, вы скоро захотите добавить к классу 'Geometry' класса' Ellipse' - 'Circle'. Это было бы здорово, поскольку вы положили глазурь на пирог;) –

Смежные вопросы