百度地图API 批量坐标转换
2021-06-17 09:03
阅读:485
标签:tab strip for 代码 target bat params 1.0 com
在将原始坐标批量转换的时候,回调的时候发现 data.status = 25
translateCallback = function (data){
//回调时 data.status = 25
}
- 1
- 2
- 3
原因是 个数非法,超过限制 百度API一次最多只支持10个点坐标转换
状态码说明
状态码 | 含义 |
0 | 正常 |
1 | 内部错误 |
21 | from非法 |
22 | to非法 |
24 | coords格式非法 |
25 | coords个数非法,超过限制 |
解决方法可以每十个点为一组,然后依次转换
以下代码可全部复制到HTML中直接运行查看
html>
head>
meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
style type="text/css">
body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
style>
script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=rmtT1e2a4k770D9jK1ouGODt">script>
title>GPS转百度批量转换title>
head>
body>
div id="allmap">div>
body>
html>
script type="text/javascript">
//所有批量转换的坐标
var points = [new BMap.Point(116.3986889372559,39.91762965106183),
new BMap.Point(116.38632786853032,39.90795884517671),
new BMap.Point(116.39534009082035,39.917432133833574),
new BMap.Point(116.41624058825688,39.91789300648029),
new BMap.Point(116.41413701159672,39.90795884517671),
new BMap.Point(116.3886889372559,39.90962965106183),
new BMap.Point(116.39632786853032,39.91795884517671),
new BMap.Point(116.37534009082035,39.907432133833574),
new BMap.Point(116.41624058825688,39.92489300648029),
new BMap.Point(116.42413701159672,39.91795884517671),
new BMap.Point(116.41413701159672,39.92795884517671),
new BMap.Point(116.40624058825688,39.93489300648029),
new BMap.Point(116.42213701159672,39.90795884517671),
new BMap.Point(116.40413701159672,39.91795884517671)
];
//地图初始化
var bm = new BMap.Map("allmap");
bm.centerAndZoom(new BMap.Point(116.378688937,39.9076296510), 15);
var total = 0; //总记录数
var groupCount = 0; //每次转十条
if (points.length % 10 > 0) {
groupCount = (points.length / 10) + 1;
}
else {
groupCount = (points.length / 10);
}
for(var i=0;i//外层循环,有多少组十条
var pos = new Array();
for(var j=0;j10;j++){ //内层循环,每组十条
if(total//不超过总记录数结束
var point = new BMap.Point(points[(i * 10) + j].lng,points[(i * 10) + j].lat);
pos.push(point);
}
total++;
}
var convertor = new BMap.Convertor();
convertor.translate(pos, 1, 5, function(data){
if(data.status === 0) {
for (var i = 0; i new BMap.Marker(data.points[i]));
bm.setCenter(data.points[i]);
}
}
});
}
script>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
演示:baidu_map_batch_conversion/
作者:itmyhome
再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow
百度地图API 批量坐标转换
标签:tab strip for 代码 target bat params 1.0 com
原文地址:https://www.cnblogs.com/skiwnchqhh/p/10333513.html
评论
亲,登录后才可以留言!