문제

I'm developing a map that is a radar, so it's not a map!

My idea setting markers on a invisible map, and instead of the classic map, set this image:

enter image description here

So, the green points would be the markers set as LAT / LON but you can't see the map, but you can see a picture.

Thanks in advance.

도움이 되었습니까?

해결책 2

i have done something like this in one of my project. i had created custom ImageView, pass lat longs and draw on the bitmap set to that ImageView.

my requirement was to draw lat long on US map.

so, you can create a custom ImageView which holds your radar image. and pass List of lat longs to that class to draw the points on the radar image.

here's my custom ImageView class.

    public class MapImageView extends ImageView{
    private float latitudeTop, latitudeBottom, longitudeRight, longitudeLeft;
    private List<Float> points = new ArrayList<Float>();
    private Paint pointPaint;
    private Matrix pointMatrix = new Matrix();

    public MapImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        pointPaint = new Paint();
        pointPaint.setAntiAlias(true);
        pointPaint.setStrokeCap(Cap.ROUND);
        pointPaint.setColor(Color.WHITE);
        pointPaint.setStrokeWidth(2.5f);
    }

    public void setBounds(float latitudeTop, float latitudeBottom, float longitudeLeft, float longitudeRight) {
        this.latitudeTop    = latitudeTop;
        this.latitudeBottom = latitudeBottom;
        this.longitudeLeft  = longitudeLeft;
        this.longitudeRight = longitudeRight;
    }

    public void addPoint(float latitude, float longitude) {
        points.add(longitude);
        points.add(latitude);
        invalidate();
    }

    public void setPoints(List<Float> points){
        this.points = points;
        LogMsg.d("PP GOT "+this.points.size());
        invalidate();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);        
        LogMsg.d("Image: -latitude: "+latitudeTop+" longitude: "+longitudeLeft);
        LogMsg.d("width: "+getMeasuredWidth()/(longitudeRight-longitudeLeft)+" Height: "+getMeasuredHeight()/(latitudeBottom-latitudeTop));
        pointMatrix.reset();
        pointMatrix.postTranslate(-longitudeLeft, -latitudeTop);
        pointMatrix.postScale(getMeasuredWidth()/(longitudeRight-longitudeLeft),getMeasuredHeight()/(latitudeBottom-latitudeTop));
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawPoints(mapPoints(), pointPaint);
    }

    private float[] mapPoints() {
        float[] pts = new float[points.size()];
        for (int i = 0; i < points.size(); i++) {
            pts[i] = points.get(i);
        }
        pointMatrix.mapPoints(pts);
        return pts;
    }
}

Here's setting bound from onCreate(), setting bound is actually the lat and longs of US Map.

mMapAppStats.setBounds(49.066668f, 25.482951f, -124.962159f, -65.932619f);

Then you can add points to this imageview like this.

for ( int i = 0 ; i < appStatsLocations.size(); i++) {
        mMapAppStats.addPoint(Float.parseFloat(appStatsLocations.get(i).getLatitude()), Float.parseFloat(appStatsLocations.get(i).getLongitude()));
    }

here's the XML.

<...MapImageView
            android:id="@+id/mapAppStats"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/btnAppStatsViewTeamNFriends"
            android:scaleType="fitXY"
            android:src="@drawable/usmapnew" />

You can get some idea from this to solve your problem.

다른 팁

You can use Google Maps for that.

  1. Implement the Google Maps SDK
  2. Make a custom "MyPositionMarker" with your picture
  3. Add some markers

Documentations: https://developers.google.com/maps/documentation/android/

EDIT: it can be easily to just calculate the offset of the markers with the user and not using a map, isn't it?

EDIT2:

    mMap = getMap();
    mMap.setMapType(GoogleMap.MAP_TYPE_NONE);
    mMap.addTileOverlay(new TileOverlayOptions().tileProvider(mProvider));

Where mProvider is a custom tiles provider.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top