Search code examples
baidu-map

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


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.


Solution

  • 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