Show directions on Baidu maps, start/end encoded in url

1.6k Views Asked by At

I can calculate directions (json) on api.map.baidu with: http://api.map.baidu.com/direction?destination=39.988710,116.432340&origin=39.940488,116.355425&mode=driving&coord_type=wgs84

How to form similar url to display same directions over map on https://map.baidu.com/

enter image description here

I would like to generate urls in my app which load directions on map.baidu.com, but it is hard to guess url because website and documentation I found is on Chinese.

2

There are 2 best solutions below

1
cody On BEST ANSWER

Through trial and error, I was able to get it to work with the following pattern:

http://api.map.baidu.com/direction?origin=latlng:39.940488,116.355425|name:origin&destination=latlng:39.988710,116.432340|name:destination&mode=driving&region=none&output=html

The differences between it and what you had include:

  • Prefixing each set of coordinates with latlng:
  • Appending |name:(point name) to each set of coordinates, it will not work without putting something here
  • Providing the output=html parameter
0
AugustYip On

Here is the API document from baidu map https://lbsyun.baidu.com/index.php?title=uri/api/web#service-page-anchor5

2.2.3 Bus, driving and walking route planning

Service address

http://api.map.baidu.com/direction //PC&Webapp service address

Examples

http://api.map.baidu.com/direction?origin=latlng:34.264642646862,108.95108518068|name:My home&destination=Great Wild Goose Pagoda&mode=driving&region=Xi'an&output=html&src=webapp.baidu.openAPIdemo

//Call up Baidu PC or Web map to show the driving directions of "Xi'an" from (lat: 34.264642646862, lng: 108.95108518068) "My home" to "Dayan Tower".