Google Maps API Version difference

2020-01-26 03:36发布

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, and following request gives perfect result:

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

Output :

Old Google Maps API


Now I try to replace this with New Google Maps API, and following request gives wrong result, In both case i'm using same source and destination, but result gives different behavior on Google Map:

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

New Google Maps API

My problem is that, New Google Maps API return less number of steps between source and destination therefore the route not showing perfect on Google Map.

Please help to resolve this problem for New Google Maps API v3.

Thanks in advance.

9条回答
一夜七次
2楼-- · 2020-01-26 04:13

It seems there are enough answers but for this subject, i benefit this link. But it didn't work when i downloaded and imported. So i implemented on my own application. And there is a mistake in that code. When you want to second time calculate a route, the app. breaks.

    if (mMarkerPoints.size() > 1) {

                mMarkerPoints.clear();
                map.clear();
                // LatLng startPoint = new LatLng(nearbyLatitude,
                // nearbyLongitude);
                // drawMarker(startPoint);
            }

Find that lines and make comment as i have done. Anyway, actually you asked to draw a route not whole code, so you can check code on that web-site. It is good at to draw route between to points (markers). Have a good day.

查看更多
贼婆χ
3楼-- · 2020-01-26 04:15

With regards to GeoPoint being unresolved, I just changed all the occurances of GeoPoint to LatLng and everything worked.

查看更多
我只想做你的唯一
4楼-- · 2020-01-26 04:19

@Ghareeb-Strange- But why would we need that with API v2? I mean, we have polyline that makes it way more easier.

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);
    }

With something like the code posted above you would have the path perfectly drawed in your app.

pathList is a List containing all the points of our path.

Cheers!

查看更多
Summer. ? 凉城
5楼-- · 2020-01-26 04:20

Please check this link..

And Specify Travel Modes

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

so you get different results.

please try it.

查看更多
趁早两清
6楼-- · 2020-01-26 04:22

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.

查看更多
Rolldiameter
7楼-- · 2020-01-26 04:23

What's new in Google Map API v3?
Google Maps Directions API v3 for Android provide routes in the Encoded Polyline Algorithm Format.

What we must have to do?
We must have to decode this Polyline for showing exact Map

How we decode this encoded Polyline provided by Google Directions API v3?
Please Refer these three links to more clear with encoded Polyline returns from the Google Maps Directions API v3

How we can resolve problem in above question?
Please refer these three answer links, that solves your problem :

查看更多
登录 后发表回答