简体   繁体   English

在Android的Google地图上绘制多边形叠加层

[英]Draw a polygon overlay on google maps in android

I parsed a KML file and I was able to extract the longitude and latitude data from it The problem now is that I am trying to draw a polygon using these data in my android application but whenever I try doing so nothing changes and I get the default map that open when I run google maps. 我解析了一个KML文件,并能够从其中提取经度和纬度数据。现在的问题是,我试图使用这些数据在android应用程序中绘制一个多边形,但是每当尝试这样做时,都没有任何变化,并且我得到了默认值运行Google地图时打开的地图。 I have tried many codes that where given as correct answers here on stackoverflow with the same geopoints given in them also nothing appeared...Does anyone have any idea about wwhat might be the problem? 我尝试了很多代码,这些代码在stackoverflow上给出了正确的答案,并且在其中给出了相同的地理点,但是也没有出现...有人对可能是什么有任何想法吗? This is the link that I tried the code in it but it is not working Drawing a line/path on Google Maps 这是我在其中尝试过代码的链接,但无法正常工作在Google Maps上绘制线/路径

Thanks in advance 提前致谢

 public void draw(Canvas canvas, MapView mapv, boolean shadow){
        super.draw(canvas, mapv, shadow);

        Paint   mPaint = new Paint();
        mPaint.setDither(true);
        mPaint.setColor(Color.RED);
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPaint.setStrokeJoin(Paint.Join.ROUND);
        mPaint.setStrokeCap(Paint.Cap.ROUND);
        mPaint.setStrokeWidth(2);

        GeoPoint gP1 = new GeoPoint(19240000,-99120000);
        GeoPoint gP2 = new GeoPoint(37423157, -122085008);

        Point p1 = new Point();
        Point p2 = new Point();
        Path path = new Path();

        projection.toPixels(gP1, p1);
        projection.toPixels(gP2, p2);

        path.moveTo(p2.x, p2.y);
        path.lineTo(p1.x,p1.y);

        canvas.drawPath(path, mPaint);
    }

Did u override the "draw()" method properly? 您是否正确重写了“ draw()”方法? is there any super() missing, or maybe dont u draw on the given canvas parameter? 是否缺少任何super(),或者您是否未在给定的canvas参数上绘制?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM