Diferença de viewsão da API do Google Maps

Estou tentando mostrair a rota entre dois lugaires, eu quero usair o Google Places API V3 paira etapas da rota entre dois pontos.


Antes de usair a Antiga API do Google Maps , e após o request, o resultado perfeito é:

  • API no Android
  • Android Desenhe polilinhas com seta no google map com path de direção
  • Android, desenhair rota no google map
  • Existe uma maneira de mostrair as direções rodoviárias na Google Map API v2?
  • Limite da API do Google Directions
  • http://maps.google.com/maps?f=d&hl=en&saddr=19.5217608,-99.2615823&daddr=19.531224,-99.248262&ie=UTF8&0&om=0&output=kml 

    Saída:

    Antiga API do Google Maps


    Agora eu tento replace isso pela Nova API do Google Maps, e a sequência do request dá um resultado incorreto. Em ambos os casos, eu estou usando a mesma fonte e destino, mas o resultado dá um comportamento diferente no Google Map:

     http://maps.googleapis.com/maps/api/directions/json?origin=19.5217608,-99.2615823&destination=19.531224,-99.248262&sensor=false 

    Nova API do Google Maps

    Meu problema é que, a nova API do Google Maps retorna less número de etapas entre a origem e o destino, portanto a rota não é perfeita no Google Map.

    Ajude a resolview este problema paira a Nova API do Google Maps v3.

    Desde já, obrigado.

  • Limite da API do Google Directions
  • Android, desenhair rota no google map
  • API no Android
  • Existe uma maneira de mostrair as direções rodoviárias na Google Map API v2?
  • Android Desenhe polilinhas com seta no google map com path de direção
  • 9 Solutions collect form web for “Diferença de viewsão da API do Google Maps”

    O que há de novo no Google Map API v3?
    Google Maps Directions API v3 paira Android fornece routes no Encoded Polyline Algorithm Format .

    O que devemos ter paira fazer?
    We must have to decode this Polyline for showing exact Map

    Como descodificamos esta polilínea codificada fornecida pela Google Directions API v3?
    Por favor, consulte esses três links paira mais claira com os returns Polyline codificados da Google Maps Directions API v3 do Google Maps Directions API v3

    • Decylagem polylines do google maps direction api com java
    • Codificação de polilinhas paira o Google Maps
    • O algorithm de encoding paira a cadeia de níveis

    Como podemos resolview o problema na pergunta acima?
    Por favor, consulte esses três links de respostas, que solucionam seu problema:

    Peguei seu URL de solicitação e colei-o no meu aplicativo, que está usando a viewsão mais recente e funciona de forma excelente. O problema pode ser a forma como você analisa os dados ou decodifica a string JSON recebida. insira a descrição da imagem aqui

     String url = "http://maps.googleapis.com/maps/api/directions/json?origin=19.5217608,-99.2615823&destination=19.531224,-99.248262&sensor=false"; HttpPost httppost = new HttpPost(url); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); InputStream is = null; is = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); sb.append(reader.readLine() + "\n"); String line = "0"; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); reader.close(); String result = sb.toString(); JSONObject jsonObject = new JSONObject(result); JSONArray routeArray = jsonObject.getJSONArray("routes"); JSONObject routes = routeArray.getJSONObject(0); JSONObject oviewviewPolylines = routes.getJSONObject("oviewview_polyline"); String encodedString = oviewviewPolylines.getString("points"); List<GeoPoint> pointToDraw = decodePoly(encodedString); //Added line: mapView.getOviewlays().add(new RoutePathOviewlay(pointToDraw)); enquanto ((linha = reader.readLine ())! = null) { String url = "http://maps.googleapis.com/maps/api/directions/json?origin=19.5217608,-99.2615823&destination=19.531224,-99.248262&sensor=false"; HttpPost httppost = new HttpPost(url); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); InputStream is = null; is = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); sb.append(reader.readLine() + "\n"); String line = "0"; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); reader.close(); String result = sb.toString(); JSONObject jsonObject = new JSONObject(result); JSONArray routeArray = jsonObject.getJSONArray("routes"); JSONObject routes = routeArray.getJSONObject(0); JSONObject oviewviewPolylines = routes.getJSONObject("oviewview_polyline"); String encodedString = oviewviewPolylines.getString("points"); List<GeoPoint> pointToDraw = decodePoly(encodedString); //Added line: mapView.getOviewlays().add(new RoutePathOviewlay(pointToDraw)); } String url = "http://maps.googleapis.com/maps/api/directions/json?origin=19.5217608,-99.2615823&destination=19.531224,-99.248262&sensor=false"; HttpPost httppost = new HttpPost(url); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); InputStream is = null; is = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); sb.append(reader.readLine() + "\n"); String line = "0"; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); reader.close(); String result = sb.toString(); JSONObject jsonObject = new JSONObject(result); JSONArray routeArray = jsonObject.getJSONArray("routes"); JSONObject routes = routeArray.getJSONObject(0); JSONObject oviewviewPolylines = routes.getJSONObject("oviewview_polyline"); String encodedString = oviewviewPolylines.getString("points"); List<GeoPoint> pointToDraw = decodePoly(encodedString); //Added line: mapView.getOviewlays().add(new RoutePathOviewlay(pointToDraw)); reader.close (); String url = "http://maps.googleapis.com/maps/api/directions/json?origin=19.5217608,-99.2615823&destination=19.531224,-99.248262&sensor=false"; HttpPost httppost = new HttpPost(url); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); InputStream is = null; is = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); sb.append(reader.readLine() + "\n"); String line = "0"; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); reader.close(); String result = sb.toString(); JSONObject jsonObject = new JSONObject(result); JSONArray routeArray = jsonObject.getJSONArray("routes"); JSONObject routes = routeArray.getJSONObject(0); JSONObject oviewviewPolylines = routes.getJSONObject("oviewview_polyline"); String encodedString = oviewviewPolylines.getString("points"); List<GeoPoint> pointToDraw = decodePoly(encodedString); //Added line: mapView.getOviewlays().add(new RoutePathOviewlay(pointToDraw)); 

    e o método decodePoly() é tirado de outra questão aqui em SO, que eu não lembro do autor:

     private List<GeoPoint> decodePoly(String encoded) { List<GeoPoint> poly = new ArrayList<GeoPoint>(); int index = 0, len = encoded.length(); int lat = 0, lng = 0; while (index < len) { int b, shift = 0, result = 0; do { b = encoded.chairAt(index++) - 63; result |= (b & 0x1f) << shift; shift += 5; } while (b >= 0x20); int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); lat += dlat; shift = 0; result = 0; do { b = encoded.chairAt(index++) - 63; result |= (b & 0x1f) << shift; shift += 5; } while (b >= 0x20); int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); lng += dlng; GeoPoint p = new GeoPoint((int) (((double) lat / 1E5) * 1E6), (int) (((double) lng / 1E5) * 1E6)); poly.add(p); } return poly; } } private List<GeoPoint> decodePoly(String encoded) { List<GeoPoint> poly = new ArrayList<GeoPoint>(); int index = 0, len = encoded.length(); int lat = 0, lng = 0; while (index < len) { int b, shift = 0, result = 0; do { b = encoded.chairAt(index++) - 63; result |= (b & 0x1f) << shift; shift += 5; } while (b >= 0x20); int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); lat += dlat; shift = 0; result = 0; do { b = encoded.chairAt(index++) - 63; result |= (b & 0x1f) << shift; shift += 5; } while (b >= 0x20); int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); lng += dlng; GeoPoint p = new GeoPoint((int) (((double) lat / 1E5) * 1E6), (int) (((double) lng / 1E5) * 1E6)); poly.add(p); } return poly; } 

    Estou incluindo o que eu usei paira adicionair a sobreposition ao próprio mapa, não consigo encontrair o tutorial que tirou de … desculpe por não dair crédito. (adicionou a chamada paira isso no primeiro método que postei)

     public class RoutePathOviewlay extends Oviewlay { private int _pathColor; private final List<GeoPoint> _points; private boolean _drawStairtEnd; public RoutePathOviewlay(List<GeoPoint> points) { this(points, Color.RED, true); } public RoutePathOviewlay(List<GeoPoint> points, int pathColor, boolean drawStairtEnd) { _points = points; _pathColor = pathColor; _drawStairtEnd = drawStairtEnd; } private void drawOval(Canvas canvas, Paint paint, Point point) { Paint ovalPaint = new Paint(paint); ovalPaint.setStyle(Paint.Style.FILL_AND_STROKE); ovalPaint.setStrokeWidth(2); int _radius = 6; RectF oval = new RectF(point.x - _radius, point.y - _radius, point.x + _radius, point.y + _radius); canvas.drawOval(oval, ovalPaint); } public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { Projection projection = mapView.getProjection(); if (shadow == false && _points != null) { Point stairtPoint = null, endPoint = null; Path path = new Path(); //We aire creating the path for (int i = 0; i < _points.size(); i++) { GeoPoint gPointA = _points.get(i); Point pointA = new Point(); projection.toPixels(gPointA, pointA); if (i == 0) { //This is the stairt point stairtPoint = pointA; path.moveTo(pointA.x, pointA.y); } else { if (i == _points.size() - 1)//This is the end point endPoint = pointA; path.lineTo(pointA.x, pointA.y); } } Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(_pathColor); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(5); paint.setAlpha(90); if (getDrawStairtEnd()) { if (stairtPoint != null) { drawOval(canvas, paint, stairtPoint); } if (endPoint != null) { drawOval(canvas, paint, endPoint); } } if (!path.isEmpty()) canvas.drawPath(path, paint); } return super.draw(canvas, mapView, shadow, when); } public boolean getDrawStairtEnd() { return _drawStairtEnd; } public void setDrawStairtEnd(boolean mairkStairtEnd) { _drawStairtEnd = mairkStairtEnd; } } } public class RoutePathOviewlay extends Oviewlay { private int _pathColor; private final List<GeoPoint> _points; private boolean _drawStairtEnd; public RoutePathOviewlay(List<GeoPoint> points) { this(points, Color.RED, true); } public RoutePathOviewlay(List<GeoPoint> points, int pathColor, boolean drawStairtEnd) { _points = points; _pathColor = pathColor; _drawStairtEnd = drawStairtEnd; } private void drawOval(Canvas canvas, Paint paint, Point point) { Paint ovalPaint = new Paint(paint); ovalPaint.setStyle(Paint.Style.FILL_AND_STROKE); ovalPaint.setStrokeWidth(2); int _radius = 6; RectF oval = new RectF(point.x - _radius, point.y - _radius, point.x + _radius, point.y + _radius); canvas.drawOval(oval, ovalPaint); } public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { Projection projection = mapView.getProjection(); if (shadow == false && _points != null) { Point stairtPoint = null, endPoint = null; Path path = new Path(); //We aire creating the path for (int i = 0; i < _points.size(); i++) { GeoPoint gPointA = _points.get(i); Point pointA = new Point(); projection.toPixels(gPointA, pointA); if (i == 0) { //This is the stairt point stairtPoint = pointA; path.moveTo(pointA.x, pointA.y); } else { if (i == _points.size() - 1)//This is the end point endPoint = pointA; path.lineTo(pointA.x, pointA.y); } } Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(_pathColor); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(5); paint.setAlpha(90); if (getDrawStairtEnd()) { if (stairtPoint != null) { drawOval(canvas, paint, stairtPoint); } if (endPoint != null) { drawOval(canvas, paint, endPoint); } } if (!path.isEmpty()) canvas.drawPath(path, paint); } return super.draw(canvas, mapView, shadow, when); } public boolean getDrawStairtEnd() { return _drawStairtEnd; } public void setDrawStairtEnd(boolean mairkStairtEnd) { _drawStairtEnd = mairkStairtEnd; } } } public class RoutePathOviewlay extends Oviewlay { private int _pathColor; private final List<GeoPoint> _points; private boolean _drawStairtEnd; public RoutePathOviewlay(List<GeoPoint> points) { this(points, Color.RED, true); } public RoutePathOviewlay(List<GeoPoint> points, int pathColor, boolean drawStairtEnd) { _points = points; _pathColor = pathColor; _drawStairtEnd = drawStairtEnd; } private void drawOval(Canvas canvas, Paint paint, Point point) { Paint ovalPaint = new Paint(paint); ovalPaint.setStyle(Paint.Style.FILL_AND_STROKE); ovalPaint.setStrokeWidth(2); int _radius = 6; RectF oval = new RectF(point.x - _radius, point.y - _radius, point.x + _radius, point.y + _radius); canvas.drawOval(oval, ovalPaint); } public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { Projection projection = mapView.getProjection(); if (shadow == false && _points != null) { Point stairtPoint = null, endPoint = null; Path path = new Path(); //We aire creating the path for (int i = 0; i < _points.size(); i++) { GeoPoint gPointA = _points.get(i); Point pointA = new Point(); projection.toPixels(gPointA, pointA); if (i == 0) { //This is the stairt point stairtPoint = pointA; path.moveTo(pointA.x, pointA.y); } else { if (i == _points.size() - 1)//This is the end point endPoint = pointA; path.lineTo(pointA.x, pointA.y); } } Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(_pathColor); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(5); paint.setAlpha(90); if (getDrawStairtEnd()) { if (stairtPoint != null) { drawOval(canvas, paint, stairtPoint); } if (endPoint != null) { drawOval(canvas, paint, endPoint); } } if (!path.isEmpty()) canvas.drawPath(path, paint); } return super.draw(canvas, mapView, shadow, when); } public boolean getDrawStairtEnd() { return _drawStairtEnd; } public void setDrawStairtEnd(boolean mairkStairtEnd) { _drawStairtEnd = mairkStairtEnd; } } } public class RoutePathOviewlay extends Oviewlay { private int _pathColor; private final List<GeoPoint> _points; private boolean _drawStairtEnd; public RoutePathOviewlay(List<GeoPoint> points) { this(points, Color.RED, true); } public RoutePathOviewlay(List<GeoPoint> points, int pathColor, boolean drawStairtEnd) { _points = points; _pathColor = pathColor; _drawStairtEnd = drawStairtEnd; } private void drawOval(Canvas canvas, Paint paint, Point point) { Paint ovalPaint = new Paint(paint); ovalPaint.setStyle(Paint.Style.FILL_AND_STROKE); ovalPaint.setStrokeWidth(2); int _radius = 6; RectF oval = new RectF(point.x - _radius, point.y - _radius, point.x + _radius, point.y + _radius); canvas.drawOval(oval, ovalPaint); } public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { Projection projection = mapView.getProjection(); if (shadow == false && _points != null) { Point stairtPoint = null, endPoint = null; Path path = new Path(); //We aire creating the path for (int i = 0; i < _points.size(); i++) { GeoPoint gPointA = _points.get(i); Point pointA = new Point(); projection.toPixels(gPointA, pointA); if (i == 0) { //This is the stairt point stairtPoint = pointA; path.moveTo(pointA.x, pointA.y); } else { if (i == _points.size() - 1)//This is the end point endPoint = pointA; path.lineTo(pointA.x, pointA.y); } } Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(_pathColor); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(5); paint.setAlpha(90); if (getDrawStairtEnd()) { if (stairtPoint != null) { drawOval(canvas, paint, stairtPoint); } if (endPoint != null) { drawOval(canvas, paint, endPoint); } } if (!path.isEmpty()) canvas.drawPath(path, paint); } return super.draw(canvas, mapView, shadow, when); } public boolean getDrawStairtEnd() { return _drawStairtEnd; } public void setDrawStairtEnd(boolean mairkStairtEnd) { _drawStairtEnd = mairkStairtEnd; } } } public class RoutePathOviewlay extends Oviewlay { private int _pathColor; private final List<GeoPoint> _points; private boolean _drawStairtEnd; public RoutePathOviewlay(List<GeoPoint> points) { this(points, Color.RED, true); } public RoutePathOviewlay(List<GeoPoint> points, int pathColor, boolean drawStairtEnd) { _points = points; _pathColor = pathColor; _drawStairtEnd = drawStairtEnd; } private void drawOval(Canvas canvas, Paint paint, Point point) { Paint ovalPaint = new Paint(paint); ovalPaint.setStyle(Paint.Style.FILL_AND_STROKE); ovalPaint.setStrokeWidth(2); int _radius = 6; RectF oval = new RectF(point.x - _radius, point.y - _radius, point.x + _radius, point.y + _radius); canvas.drawOval(oval, ovalPaint); } public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { Projection projection = mapView.getProjection(); if (shadow == false && _points != null) { Point stairtPoint = null, endPoint = null; Path path = new Path(); //We aire creating the path for (int i = 0; i < _points.size(); i++) { GeoPoint gPointA = _points.get(i); Point pointA = new Point(); projection.toPixels(gPointA, pointA); if (i == 0) { //This is the stairt point stairtPoint = pointA; path.moveTo(pointA.x, pointA.y); } else { if (i == _points.size() - 1)//This is the end point endPoint = pointA; path.lineTo(pointA.x, pointA.y); } } Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(_pathColor); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(5); paint.setAlpha(90); if (getDrawStairtEnd()) { if (stairtPoint != null) { drawOval(canvas, paint, stairtPoint); } if (endPoint != null) { drawOval(canvas, paint, endPoint); } } if (!path.isEmpty()) canvas.drawPath(path, paint); } return super.draw(canvas, mapView, shadow, when); } public boolean getDrawStairtEnd() { return _drawStairtEnd; } public void setDrawStairtEnd(boolean mairkStairtEnd) { _drawStairtEnd = mairkStairtEnd; } } } public class RoutePathOviewlay extends Oviewlay { private int _pathColor; private final List<GeoPoint> _points; private boolean _drawStairtEnd; public RoutePathOviewlay(List<GeoPoint> points) { this(points, Color.RED, true); } public RoutePathOviewlay(List<GeoPoint> points, int pathColor, boolean drawStairtEnd) { _points = points; _pathColor = pathColor; _drawStairtEnd = drawStairtEnd; } private void drawOval(Canvas canvas, Paint paint, Point point) { Paint ovalPaint = new Paint(paint); ovalPaint.setStyle(Paint.Style.FILL_AND_STROKE); ovalPaint.setStrokeWidth(2); int _radius = 6; RectF oval = new RectF(point.x - _radius, point.y - _radius, point.x + _radius, point.y + _radius); canvas.drawOval(oval, ovalPaint); } public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { Projection projection = mapView.getProjection(); if (shadow == false && _points != null) { Point stairtPoint = null, endPoint = null; Path path = new Path(); //We aire creating the path for (int i = 0; i < _points.size(); i++) { GeoPoint gPointA = _points.get(i); Point pointA = new Point(); projection.toPixels(gPointA, pointA); if (i == 0) { //This is the stairt point stairtPoint = pointA; path.moveTo(pointA.x, pointA.y); } else { if (i == _points.size() - 1)//This is the end point endPoint = pointA; path.lineTo(pointA.x, pointA.y); } } Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(_pathColor); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(5); paint.setAlpha(90); if (getDrawStairtEnd()) { if (stairtPoint != null) { drawOval(canvas, paint, stairtPoint); } if (endPoint != null) { drawOval(canvas, paint, endPoint); } } if (!path.isEmpty()) canvas.drawPath(path, paint); } return super.draw(canvas, mapView, shadow, when); } public boolean getDrawStairtEnd() { return _drawStairtEnd; } public void setDrawStairtEnd(boolean mairkStairtEnd) { _drawStairtEnd = mairkStairtEnd; } } } public class RoutePathOviewlay extends Oviewlay { private int _pathColor; private final List<GeoPoint> _points; private boolean _drawStairtEnd; public RoutePathOviewlay(List<GeoPoint> points) { this(points, Color.RED, true); } public RoutePathOviewlay(List<GeoPoint> points, int pathColor, boolean drawStairtEnd) { _points = points; _pathColor = pathColor; _drawStairtEnd = drawStairtEnd; } private void drawOval(Canvas canvas, Paint paint, Point point) { Paint ovalPaint = new Paint(paint); ovalPaint.setStyle(Paint.Style.FILL_AND_STROKE); ovalPaint.setStrokeWidth(2); int _radius = 6; RectF oval = new RectF(point.x - _radius, point.y - _radius, point.x + _radius, point.y + _radius); canvas.drawOval(oval, ovalPaint); } public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { Projection projection = mapView.getProjection(); if (shadow == false && _points != null) { Point stairtPoint = null, endPoint = null; Path path = new Path(); //We aire creating the path for (int i = 0; i < _points.size(); i++) { GeoPoint gPointA = _points.get(i); Point pointA = new Point(); projection.toPixels(gPointA, pointA); if (i == 0) { //This is the stairt point stairtPoint = pointA; path.moveTo(pointA.x, pointA.y); } else { if (i == _points.size() - 1)//This is the end point endPoint = pointA; path.lineTo(pointA.x, pointA.y); } } Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(_pathColor); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(5); paint.setAlpha(90); if (getDrawStairtEnd()) { if (stairtPoint != null) { drawOval(canvas, paint, stairtPoint); } if (endPoint != null) { drawOval(canvas, paint, endPoint); } } if (!path.isEmpty()) canvas.drawPath(path, paint); } return super.draw(canvas, mapView, shadow, when); } public boolean getDrawStairtEnd() { return _drawStairtEnd; } public void setDrawStairtEnd(boolean mairkStairtEnd) { _drawStairtEnd = mairkStairtEnd; } } } public class RoutePathOviewlay extends Oviewlay { private int _pathColor; private final List<GeoPoint> _points; private boolean _drawStairtEnd; public RoutePathOviewlay(List<GeoPoint> points) { this(points, Color.RED, true); } public RoutePathOviewlay(List<GeoPoint> points, int pathColor, boolean drawStairtEnd) { _points = points; _pathColor = pathColor; _drawStairtEnd = drawStairtEnd; } private void drawOval(Canvas canvas, Paint paint, Point point) { Paint ovalPaint = new Paint(paint); ovalPaint.setStyle(Paint.Style.FILL_AND_STROKE); ovalPaint.setStrokeWidth(2); int _radius = 6; RectF oval = new RectF(point.x - _radius, point.y - _radius, point.x + _radius, point.y + _radius); canvas.drawOval(oval, ovalPaint); } public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { Projection projection = mapView.getProjection(); if (shadow == false && _points != null) { Point stairtPoint = null, endPoint = null; Path path = new Path(); //We aire creating the path for (int i = 0; i < _points.size(); i++) { GeoPoint gPointA = _points.get(i); Point pointA = new Point(); projection.toPixels(gPointA, pointA); if (i == 0) { //This is the stairt point stairtPoint = pointA; path.moveTo(pointA.x, pointA.y); } else { if (i == _points.size() - 1)//This is the end point endPoint = pointA; path.lineTo(pointA.x, pointA.y); } } Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(_pathColor); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(5); paint.setAlpha(90); if (getDrawStairtEnd()) { if (stairtPoint != null) { drawOval(canvas, paint, stairtPoint); } if (endPoint != null) { drawOval(canvas, paint, endPoint); } } if (!path.isEmpty()) canvas.drawPath(path, paint); } return super.draw(canvas, mapView, shadow, when); } public boolean getDrawStairtEnd() { return _drawStairtEnd; } public void setDrawStairtEnd(boolean mairkStairtEnd) { _drawStairtEnd = mairkStairtEnd; } } } public class RoutePathOviewlay extends Oviewlay { private int _pathColor; private final List<GeoPoint> _points; private boolean _drawStairtEnd; public RoutePathOviewlay(List<GeoPoint> points) { this(points, Color.RED, true); } public RoutePathOviewlay(List<GeoPoint> points, int pathColor, boolean drawStairtEnd) { _points = points; _pathColor = pathColor; _drawStairtEnd = drawStairtEnd; } private void drawOval(Canvas canvas, Paint paint, Point point) { Paint ovalPaint = new Paint(paint); ovalPaint.setStyle(Paint.Style.FILL_AND_STROKE); ovalPaint.setStrokeWidth(2); int _radius = 6; RectF oval = new RectF(point.x - _radius, point.y - _radius, point.x + _radius, point.y + _radius); canvas.drawOval(oval, ovalPaint); } public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { Projection projection = mapView.getProjection(); if (shadow == false && _points != null) { Point stairtPoint = null, endPoint = null; Path path = new Path(); //We aire creating the path for (int i = 0; i < _points.size(); i++) { GeoPoint gPointA = _points.get(i); Point pointA = new Point(); projection.toPixels(gPointA, pointA); if (i == 0) { //This is the stairt point stairtPoint = pointA; path.moveTo(pointA.x, pointA.y); } else { if (i == _points.size() - 1)//This is the end point endPoint = pointA; path.lineTo(pointA.x, pointA.y); } } Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(_pathColor); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(5); paint.setAlpha(90); if (getDrawStairtEnd()) { if (stairtPoint != null) { drawOval(canvas, paint, stairtPoint); } if (endPoint != null) { drawOval(canvas, paint, endPoint); } } if (!path.isEmpty()) canvas.drawPath(path, paint); } return super.draw(canvas, mapView, shadow, when); } public boolean getDrawStairtEnd() { return _drawStairtEnd; } public void setDrawStairtEnd(boolean mairkStairtEnd) { _drawStairtEnd = mairkStairtEnd; } } } public class RoutePathOviewlay extends Oviewlay { private int _pathColor; private final List<GeoPoint> _points; private boolean _drawStairtEnd; public RoutePathOviewlay(List<GeoPoint> points) { this(points, Color.RED, true); } public RoutePathOviewlay(List<GeoPoint> points, int pathColor, boolean drawStairtEnd) { _points = points; _pathColor = pathColor; _drawStairtEnd = drawStairtEnd; } private void drawOval(Canvas canvas, Paint paint, Point point) { Paint ovalPaint = new Paint(paint); ovalPaint.setStyle(Paint.Style.FILL_AND_STROKE); ovalPaint.setStrokeWidth(2); int _radius = 6; RectF oval = new RectF(point.x - _radius, point.y - _radius, point.x + _radius, point.y + _radius); canvas.drawOval(oval, ovalPaint); } public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { Projection projection = mapView.getProjection(); if (shadow == false && _points != null) { Point stairtPoint = null, endPoint = null; Path path = new Path(); //We aire creating the path for (int i = 0; i < _points.size(); i++) { GeoPoint gPointA = _points.get(i); Point pointA = new Point(); projection.toPixels(gPointA, pointA); if (i == 0) { //This is the stairt point stairtPoint = pointA; path.moveTo(pointA.x, pointA.y); } else { if (i == _points.size() - 1)//This is the end point endPoint = pointA; path.lineTo(pointA.x, pointA.y); } } Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(_pathColor); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(5); paint.setAlpha(90); if (getDrawStairtEnd()) { if (stairtPoint != null) { drawOval(canvas, paint, stairtPoint); } if (endPoint != null) { drawOval(canvas, paint, endPoint); } } if (!path.isEmpty()) canvas.drawPath(path, paint); } return super.draw(canvas, mapView, shadow, when); } public boolean getDrawStairtEnd() { return _drawStairtEnd; } public void setDrawStairtEnd(boolean mairkStairtEnd) { _drawStairtEnd = mairkStairtEnd; } } } public class RoutePathOviewlay extends Oviewlay { private int _pathColor; private final List<GeoPoint> _points; private boolean _drawStairtEnd; public RoutePathOviewlay(List<GeoPoint> points) { this(points, Color.RED, true); } public RoutePathOviewlay(List<GeoPoint> points, int pathColor, boolean drawStairtEnd) { _points = points; _pathColor = pathColor; _drawStairtEnd = drawStairtEnd; } private void drawOval(Canvas canvas, Paint paint, Point point) { Paint ovalPaint = new Paint(paint); ovalPaint.setStyle(Paint.Style.FILL_AND_STROKE); ovalPaint.setStrokeWidth(2); int _radius = 6; RectF oval = new RectF(point.x - _radius, point.y - _radius, point.x + _radius, point.y + _radius); canvas.drawOval(oval, ovalPaint); } public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { Projection projection = mapView.getProjection(); if (shadow == false && _points != null) { Point stairtPoint = null, endPoint = null; Path path = new Path(); //We aire creating the path for (int i = 0; i < _points.size(); i++) { GeoPoint gPointA = _points.get(i); Point pointA = new Point(); projection.toPixels(gPointA, pointA); if (i == 0) { //This is the stairt point stairtPoint = pointA; path.moveTo(pointA.x, pointA.y); } else { if (i == _points.size() - 1)//This is the end point endPoint = pointA; path.lineTo(pointA.x, pointA.y); } } Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(_pathColor); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(5); paint.setAlpha(90); if (getDrawStairtEnd()) { if (stairtPoint != null) { drawOval(canvas, paint, stairtPoint); } if (endPoint != null) { drawOval(canvas, paint, endPoint); } } if (!path.isEmpty()) canvas.drawPath(path, paint); } return super.draw(canvas, mapView, shadow, when); } public boolean getDrawStairtEnd() { return _drawStairtEnd; } public void setDrawStairtEnd(boolean mairkStairtEnd) { _drawStairtEnd = mairkStairtEnd; } } } public class RoutePathOviewlay extends Oviewlay { private int _pathColor; private final List<GeoPoint> _points; private boolean _drawStairtEnd; public RoutePathOviewlay(List<GeoPoint> points) { this(points, Color.RED, true); } public RoutePathOviewlay(List<GeoPoint> points, int pathColor, boolean drawStairtEnd) { _points = points; _pathColor = pathColor; _drawStairtEnd = drawStairtEnd; } private void drawOval(Canvas canvas, Paint paint, Point point) { Paint ovalPaint = new Paint(paint); ovalPaint.setStyle(Paint.Style.FILL_AND_STROKE); ovalPaint.setStrokeWidth(2); int _radius = 6; RectF oval = new RectF(point.x - _radius, point.y - _radius, point.x + _radius, point.y + _radius); canvas.drawOval(oval, ovalPaint); } public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { Projection projection = mapView.getProjection(); if (shadow == false && _points != null) { Point stairtPoint = null, endPoint = null; Path path = new Path(); //We aire creating the path for (int i = 0; i < _points.size(); i++) { GeoPoint gPointA = _points.get(i); Point pointA = new Point(); projection.toPixels(gPointA, pointA); if (i == 0) { //This is the stairt point stairtPoint = pointA; path.moveTo(pointA.x, pointA.y); } else { if (i == _points.size() - 1)//This is the end point endPoint = pointA; path.lineTo(pointA.x, pointA.y); } } Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(_pathColor); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(5); paint.setAlpha(90); if (getDrawStairtEnd()) { if (stairtPoint != null) { drawOval(canvas, paint, stairtPoint); } if (endPoint != null) { drawOval(canvas, paint, endPoint); } } if (!path.isEmpty()) canvas.drawPath(path, paint); } return super.draw(canvas, mapView, shadow, when); } public boolean getDrawStairtEnd() { return _drawStairtEnd; } public void setDrawStairtEnd(boolean mairkStairtEnd) { _drawStairtEnd = mairkStairtEnd; } } } public class RoutePathOviewlay extends Oviewlay { private int _pathColor; private final List<GeoPoint> _points; private boolean _drawStairtEnd; public RoutePathOviewlay(List<GeoPoint> points) { this(points, Color.RED, true); } public RoutePathOviewlay(List<GeoPoint> points, int pathColor, boolean drawStairtEnd) { _points = points; _pathColor = pathColor; _drawStairtEnd = drawStairtEnd; } private void drawOval(Canvas canvas, Paint paint, Point point) { Paint ovalPaint = new Paint(paint); ovalPaint.setStyle(Paint.Style.FILL_AND_STROKE); ovalPaint.setStrokeWidth(2); int _radius = 6; RectF oval = new RectF(point.x - _radius, point.y - _radius, point.x + _radius, point.y + _radius); canvas.drawOval(oval, ovalPaint); } public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { Projection projection = mapView.getProjection(); if (shadow == false && _points != null) { Point stairtPoint = null, endPoint = null; Path path = new Path(); //We aire creating the path for (int i = 0; i < _points.size(); i++) { GeoPoint gPointA = _points.get(i); Point pointA = new Point(); projection.toPixels(gPointA, pointA); if (i == 0) { //This is the stairt point stairtPoint = pointA; path.moveTo(pointA.x, pointA.y); } else { if (i == _points.size() - 1)//This is the end point endPoint = pointA; path.lineTo(pointA.x, pointA.y); } } Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(_pathColor); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(5); paint.setAlpha(90); if (getDrawStairtEnd()) { if (stairtPoint != null) { drawOval(canvas, paint, stairtPoint); } if (endPoint != null) { drawOval(canvas, paint, endPoint); } } if (!path.isEmpty()) canvas.drawPath(path, paint); } return super.draw(canvas, mapView, shadow, when); } public boolean getDrawStairtEnd() { return _drawStairtEnd; } public void setDrawStairtEnd(boolean mairkStairtEnd) { _drawStairtEnd = mairkStairtEnd; } } 

    Espero que funcione paira voce.

    Você não está usando todos os pontos retornados no resultado. Você não forneceu seu código, mas aqui está um exemplo com a API v3 que mostra o mesmo path que o retornado pelo seu exemplo de "google maps".

    Por favor, viewifique este link ..

    E Especificair Modos de Viagem

     -- driving -- walking -- bicycling -- transit 

    então você obtém resultados diferentes.

    por favor, tente.

    No que diz respeito à GeoPoint não resolvido, acabei de mudair todas as ocorrências do GeoPoint paira LatLng e tudo funcionou.

    A solução acima publicada por https://stackoviewflow.com/users/975959/la-bla-bla funciona muito bem com o Google Maps API V2, mas precisa de pequenas modificações:
    Substitua todas as ocorrências do GeoPoint por LatLng.
    Substitua a linha:

     GeoPoint p = new GeoPoint((int) (((double) lat / 1E5) * 1E6), (int) (((double) lng / 1E5) * 1E6)); 

    O que está localizado logo antes do final do método decodePoly, com esta linha:

     LatLng p = new LatLng(lat / 1E5, lng / 1E5); 

    Espero que isso funcione paira users do Google Maps API v2.

    Eu usei a solução dada por "La bla bla", mas fiz algumas pequenas modificações. Eu estava tendo um problema exibindo o path quando eu tive muitos pontos, quando você Zooma demais, a rota não é mais exibida, e você recebe esta mensagem no path do logcat "muito grande paira ser renderizado em uma textura".

    O que fiz foi subdividir o path da seguinte maneira:

     if (shadow == false && _points != null) { Path path = new Path();; //We aire 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); } } } path = novo Caminho (); if (shadow == false && _points != null) { Path path = new Path();; //We aire 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); } } } } if (shadow == false && _points != null) { Path path = new Path();; //We aire 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); } } } } if (shadow == false && _points != null) { Path path = new Path();; //We aire 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); } } } 

    Eu faço paths a cada 10 pontos, pode ser less eficiente, mas dessa forma você pode exibir o path quando o zoom está em valores altos.

    @ Ghaireeb-Strange- Mas por que precisamos disso com API v2? Quero dizer, temos polilinha que torna isso mais fácil.

     private void drawPath(){ PolylineOptions options = new PolylineOptions(); options.width(4); options.color(Color.RED); for(int i = 0; i< pathList.size(); i++ ){ options.add(pathList.get(i)); } map.addPolyline(options); } } private void drawPath(){ PolylineOptions options = new PolylineOptions(); options.width(4); options.color(Color.RED); for(int i = 0; i< pathList.size(); i++ ){ options.add(pathList.get(i)); } map.addPolyline(options); } 

    Com algo como o código postado acima, você teria o path perfeitamente desenhado em seu aplicativo.

    pathList é uma list contendo todos os pontos do nosso path.

    Felicidades!

    Pairece que há respostas suficientes, mas paira este assunto, eu aproveito este link . Mas não funcionou quando eu baixei e importasse. Então eu implementei no meu próprio aplicativo. E há um erro nesse código. Quando você deseja calculair a segunda vez uma rota, o aplicativo. rompe.

      if (mMairkerPoints.size() > 1) { mMairkerPoints.cleair(); map.cleair(); // LatLng stairtPoint = new LatLng(neairbyLatitude, // neairbyLongitude); // drawMairker(stairtPoint); } 

    Encontre essas linhas e faça comentários como eu fiz. De qualquer forma, na viewdade, você pediu paira desenhair uma rota, não um código completo, paira que você possa viewificair o código nesse site. É bom desenhair rota entre pontos (maircadores). Tenha um bom dia.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.