百度地图的命令行API
./addr2geo.sh 广州塔 | xargs ./geo2point.sh | xargs ./point2coord.sh
./coord2point.sh 113.330995, 23.112229 | xargs ./point2addr.sh
caiguanhao c8d6a16d1d add text color and fix typo; | vor 11 Jahren | |
---|---|---|
.tests.sh | vor 11 Jahren | |
.travis.yml | vor 11 Jahren | |
LICENSE | vor 11 Jahren | |
README.md | vor 11 Jahren | |
addr2geo.sh | vor 11 Jahren | |
addr2point.sh | vor 11 Jahren | |
coord2point.sh | vor 11 Jahren | |
geo2point.sh | vor 11 Jahren | |
gmaps2bdmaps.sh | vor 11 Jahren | |
point2addr.sh | vor 11 Jahren | |
point2coord.sh | vor 11 Jahren |
Use these utils to automatically fetch coordinates of large quantities of addresses in China. These coordinates may be used as the default coordinates of the embeded Baidu Maps in web pages. Note that the way how Baidu Maps represent its coordinates is different from the rest of the world.
Address to coordinates
$ bash addr2geo.sh 广州塔 | xargs bash geo2point.sh | xargs bash point2coord.sh
113.331110, 23.112097
Coordinates to address
$ bash coord2point.sh 113.331110, 23.112097 | xargs bash point2addr.sh
广东省广州市海珠区艺苑路
Returns the GEO string of the first search result for specified Chinese address in Baidu Maps. If no search results returned, try to remove last character and search again until GEO string is found.
$ bash addr2geo.sh 广州塔
.=UOqMLBsMwqPA;
Returns the point directly and fuzzily. Note that the script will sometimes return nothing if address is too short (for example, address without the name of the city). If the address is too long or does not exist, it will return a nearby point.
$ bash addr2point.sh 广州塔
12616023.37, 2628610.59
The argument supports GEO string with only one point. For those strings with multiple points, you may either use Baidu's JavaScript functions to convert them or split the string by ';' and treat each part as an argument to this script.
Points in multi-point GEO string share the same GEO type, which is determined by the first character of the string. A possible multi-point GEO string may look like this: .=LmIPNBjMOxcA;=LmIPNBjMOxcA;
.
$ bash geo2point.sh ".=UOqMLBsMwqPA;"
12616098.76, 2628657.08
$ bash point2coord.sh 12616098.76, 2628657.08
113.331110, 23.112097
$ bash coord2point.sh 113.331110, 23.112097
12616098.73, 2628657.09
Find the possible address to the point.
$ bash point2addr.sh 12616098.76, 2628657.08
广东省广州市海珠区艺苑路
$ bash gmaps2bdmaps.sh 23.10641, 113.32449
113.3310312352, 23.112174790841
convertMC2LL: function
and add a breakpoint inside the function by clicking the line number.
Q(".=LmIPNBjMOxcA;=LmIPNBjMOxcA;")
Most of Linux/Unix based operating systems have these software pre-installed.
You can run bash .tests.sh
to see if this tool works.
利用 cURL 访问百度地图公开的 API ,搜索地址,从结果中获取GEO字符串,如果没有结果,会删除最后一个字符,继续搜索,直至有结果为止。百度把地图上点的坐标“加密”成为GEO字符串,点的坐标又要经过运算才可得到经纬坐标。百度表示坐标的方法和正常的表示方法相反。
我在百度上找不到可以直接转换或者获取坐标的方法。
利用这个脚本可以快速获取大批地址对应的坐标,这些坐标可以作为各网站上嵌入的百度地图的默认坐标。