Google Maps API Version difference

后端 未结 9 1650
野趣味
野趣味 2020-11-28 23:22

I\'m trying to show route between two places, I want to used Google Places API V3 for route steps between two points.


Before I was using Old Google Maps API, a

9条回答
  •  伪装坚强ぢ
    2020-11-29 00:05

    I used the solution given by "La bla bla", but I made some little modifications. I was having an issue displaying the path when i had too many points, when you Zoom in too much, the route is not displayed anymore, and you get this message in logcat "shape path too large to be rendered into a texture".

    What I did was to subdivide the path in the following way:

    if (shadow == false && _points != null) {
            Path path = new Path();;
            //We are creating the path
            Point pointA = new Point();
            for (int i = 0; i < _points.size(); i++) {
                mapView.getProjection().toPixels(_points.get(i), pointA);
                if (i == 0) path.moveTo(pointA.x, pointA.y);                
                else path.lineTo(pointA.x, pointA.y);
    
                if(i%10==0 || i == _points.size()-1){
                    Paint paint = new Paint();
                    paint.setAntiAlias(true);
                    paint.setColor(_pathColor);
                    paint.setStyle(Paint.Style.STROKE);
                    paint.setStrokeJoin(Paint.Join.ROUND);
                    paint.setStrokeCap(Paint.Cap.ROUND);
                    paint.setStrokeWidth(mapView.getZoomLevel()-10);
                    paint.setAlpha(200);
                    if (!path.isEmpty()) canvas.drawPath(path, paint);
                    path = new Path();
                    path.moveTo(pointA.x, pointA.y);
                }
            }
        }
    

    I make paths every 10 points, it can be less efficient, but this way you can display the path when the zoom is in high values.

提交回复
热议问题