放大Android开发 - 谷歌地图变慢 [英] Zooming on android dev - google maps becomes slower

查看:90
本文介绍了放大Android开发 - 谷歌地图变慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了GPS应用程序中,我记录用户的路线,并显示在地图上。但是,回顾我的路线时,在地图上平移周围是痛苦的缓慢,至少需要4或5秒,地图响应手指挥笔。

我重写的onDraw()方法,并绘制线条显示路线,每当我们缩放地图上,纬度长再通过调用的onDraw()(覆盖)方法,这与纬度的geopoints绘制-lon值,因而变得很慢,显示在地图上。有没有更好的办法做到这一点,使声像变快,作为应用程序MyTracks?

以下是code绘制在地图上的路线。请查看一下,告诉我我怎样才能使其更有效率,这样的平移和缩放效果很好。

 类PathOverlay扩展覆盖{
  公共PathOverlay(){
        // TODO自动生成构造函数存根
        geopoints =新的ArrayList<&GeoPoint的GT;();
        c.moveToFirst();
        的for(int i = 0; I< c.getCount();我++){            如果(c.getDouble(c.getColumnIndex(纬度))!= 0.0 ||
                    c.getDouble(c.getColumnIndex(经度))!= 0.0){                geopoints.add(用GetPoint(c.getDouble(c.getColumnIndex(纬度))
                        ,c.getDouble(c.getColumnIndex(经度))));
                gps_status.add(Boolean.parseBoolean(c.getString(c.getColumnIndex(GPS))));
                avgeSpeed​​_points.add(c.getFloat(9));
            }
            c.moveToNext();
        }    }
    私人的GeoPoint用GetPoint(双纬度,双LON){
        返回(新的GeoPoint((int)的(纬度* 1000000.0),(INT)(LON * 1000000.0)));
    }    @覆盖
    公共无效画(油画画布,MapView类MapView类,布尔阴影){    // super.draw(画布,MapView类,阴影);
        mapView.getDrawingCache();        涂料paint_Line =新的油漆();
        //paint_Line.setColor(Color.RED);
        paint_Line.setARGB(255,255,0,0);
        paint_Line.setStrokeWidth(3);
        paint_Line.setDither(真);
        paint_Line.setStyle(Style.FILL);
        paint_Line.setAntiAlias​​(真);
        paint_Line.setStrokeJoin(Paint.Join.ROUND);
        paint_Line.setStrokeCap​​(Paint.Cap.ROUND);        mapView.postInvalidateDelayed(6000);
        的for(int i = 0; I< geopoints.size() - 1;我++){            点P1 =新点();
            点P2 =新点();            如果((geopoints.get(ⅰ).getLatitudeE6()!= geopoints.get第(i + 1).getLatitudeE6())
                    &功放;&安培; (geopoints.get(ⅰ).getLongitudeE6()!= geopoints.get第(i + 1).getLongitudeE6())
                    &功放;&安培; gps_status.get第(i + 1)){
            paint_Line.setColor(Color.BLUE);
            MapView.getProjection()在toPixels(geopoints.get(i)中,P1)。
            MapView.getProjection()在toPixels(geopoints.get第(i + 1),P 2)。
            canvas.drawLine(p1.x,p1.y,p2.x,p2.y,paint_Line);
           }            MapView.getProjection()在toPixels(geopoints.get(i)中,P1)。
            如果(我== 0){
                canvas.drawBitmap(开始,p1.x-2,p1.y-start.getHeight()+ 2为空);
            }
            如果第(i + 1 == geopoints.size() - 1){
                canvas.drawBitmap(光洁度,p1.x-2,p1.y-finish.getHeight()+ 2为空);
            }
        }
    }}


解决方案

可以保存指向KML你的服务器上的文件?
尝试创建premade KML具有相同点的文件,并用它添加到地图

 意图mapIntent =新意图(Intent.ACTION_VIEW,URI);
乌里uri1 = Uri.parse(地理:0,0 Q = HTTP://$c$c.google.com/apis/kml/documentation/KML_Samples.kml?);
mapIntent.setData(uri1);
startActivity(Intent.createChooser(mapIntent,样品图));

如果在速度更快,那么你应该看看这个方法,而不是写自己的绘制方法。 KML是XML的一种形式,所以你可以以同样的方式创建它。记得样式(颜色等)添加到KML文件。

I've developed a GPS app in which i record the user routes and show it on the map. But panning around on the map when reviewing my route is painfully slow, it takes at least 4 or 5 seconds for the map to respond the finger swipes.

I've overridden the onDraw() method and drawing the lines to show the routes whenever we zoom on the map, the lat-long is again drawn by calling onDraw()(Overridden) method, which has the geopoints with lat-lon values, and thus it becomes very slow to display the map. Is there any better way to do this so that panning becomes faster as in the application "MyTracks"?

Following is the code to draw the routes on map. Please look into it and show me how I can make it more efficient so that the panning and zooming works well.

class PathOverlay extends Overlay{
  public PathOverlay() {
        // TODO Auto-generated constructor stub
        geopoints=new ArrayList<GeoPoint>();
        c.moveToFirst();
        for (int i = 0; i <c.getCount() ; i++){

            if(c.getDouble(c.getColumnIndex("latitude")) != 0.0 ||
                    c.getDouble(c.getColumnIndex("longitude"))!=0.0) {

                geopoints.add(getPoint(c.getDouble(c.getColumnIndex("latitude"))
                        , c.getDouble(c.getColumnIndex("longitude"))));
                gps_status.add(Boolean.parseBoolean(c.getString(c.getColumnIndex("gps") )));
                avgeSpeed_points.add(c.getFloat(9));
            }
            c.moveToNext();


        }

    }
    private GeoPoint getPoint(double lat, double lon) {
        return(new GeoPoint((int)(lat*1000000.0),(int)(lon*1000000.0)));
    }

    @Override
    public void draw(Canvas canvas, MapView mapView, boolean shadow) {

    //  super.draw(canvas, mapView, shadow);
        mapView.getDrawingCache();

        Paint paint_Line=new Paint();
        //paint_Line.setColor(Color.RED);
        paint_Line.setARGB(255, 255, 0, 0);
        paint_Line.setStrokeWidth(3);
        paint_Line.setDither(true);
        paint_Line.setStyle(Style.FILL);
        paint_Line.setAntiAlias(true);
        paint_Line.setStrokeJoin(Paint.Join.ROUND);
        paint_Line.setStrokeCap(Paint.Cap.ROUND);



        mapView.postInvalidateDelayed(6000);


        for(int i=0;i<geopoints.size()-1;i++) {

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

            if((geopoints.get(i).getLatitudeE6()!=geopoints.get(i+1).getLatitudeE6())
                    && (geopoints.get(i).getLongitudeE6()!=geopoints.get(i+1).getLongitudeE6())
                    && gps_status.get(i+1)){
            paint_Line.setColor(Color.BLUE);
            mapView.getProjection().toPixels(geopoints.get(i), p1);
            mapView.getProjection().toPixels(geopoints.get(i+1),p2);
            canvas.drawLine(p1.x,p1.y,p2.x,p2.y,paint_Line);
           }    

            mapView.getProjection().toPixels(geopoints.get(i),p1);
            if(i==0){
                canvas.drawBitmap(start, p1.x-2, p1.y-start.getHeight()+2, null);
            }
            if (i+1==geopoints.size()-1) {
                canvas.drawBitmap(finish, p1.x-2, p1.y-finish.getHeight()+2, null);
            }   
        }






    }

}

解决方案

Can you save the points to a KML file on your server? Try creating a premade KML file with the same points and adding it to the map using:

Intent mapIntent = new Intent(Intent.ACTION_VIEW, uri);
Uri uri1 = Uri.parse("geo:0,0?q=http://code.google.com/apis/kml/documentation/KML_Samples.kml");
mapIntent.setData(uri1);
startActivity(Intent.createChooser(mapIntent, "Sample Map ")); 

If the speeds are much faster then you should look at this approach rather than writing your own draw method. KML is a form of XML so you can create it in the same manner. remember to add the style (colours etc.) to the KML file.

这篇关于放大Android开发 - 谷歌地图变慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆