简体   繁体   中英

How to draw and navigate routes on Google Maps

I want to draw routes on Google Maps (walk or drive), I want to give intent the current user coordinates and the destination coordinates, to draw and navigate the route, as this image

在此处输入图片说明

I used this code

Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr=20.344,34.34&daddr=20.5666,45.345")); startActivity(intent);

but I got "No route found"

Thanks a lot

You can't do that with intent. You should use JSON request with http://maps.googleapis.com/maps/api/directions/output?parameters. If you use JSON request, you must make it like this example, just add your coordinates : String url = "http://maps.googleapis.com/maps/api/directions/json?origin="yourlat","yourlong"&destination="secondlat","secondlong"&sensor=false";

This may help: Android draw route on a Mapview with twoo POI-s and this How do I draw a KML file on a MapView in Android?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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