# 官网API

# 常见问题

# INVALID_USER_SCODE 无效用户代码

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
    <script type="text/javascript">
      // 一定要安全密钥先写在前,key在后,不然无效
      window._AMapSecurityConfig = {
        securityJsCode: "高德安全密钥",
      }
    </script>
    <script src="http://webapi.amap.com/maps?v=2.0&key=你申请的key"></script>
    <script src="//webapi.amap.com/ui/1.0/main.js?v=1.0.11"></script>
    <title>这是一个WEB应用标题</title>
  </head>
  <body>
    <div id="root"></div>
  </body>
</html>

# 为什么调用setCenter/setFitView等接口,或者地图移动时,地图 JS API 底图不会在移动过程中刷新?

地图移动时如果希望底图也更新,可以在加载JSAPI 2.0前设置环境变量window['movingDraw']=true,但这可能会增加对浏览器的绘制性能要求。

# 高德、腾讯、百度实时路况切片地址

# 腾讯地图实时路况切片地址
https://rtt2b.map.qq.com/rtt/?z={z}&x={x}&y={reverseY}×=1&time='+longTime+'

# 高德地图实时路况切片地址
http://tm.amap.com/trafficengine/mapabc/traffictile?v=1.0&=&=&t=1&t=’+longTime+’&x={x}&y={y}&z={z}

# 百度地图实时路况切片地址(无标注)
http://its.map.baidu.com:8002/traffic/TrafficTileService?level={z}&x={x}&y={y}&time=’+longTime+’$&v=081&scaler=1

注意longTime为long值的时间戳:

//获取当前时间
var nowDate = new Date();
var year = nowDate.getFullYear();
var month = nowDate.getMonth() + 1;
var today = nowDate.getDate();
var hours = nowDate.getHours();
var minutes = nowDate.getMinutes();
var seconds = nowDate.getSeconds();

if (month >= 1 && month <= 9) {
	month = "0" + month;
}
if (today >= 1 && today <= 9) {
	today = "0" + today;
}
var currentdate = year + "-" + month + "-" + today 
                 + " " + hours + ":" + minutes + ":" + seconds;
var longTime = new Date(currentdate.replace(new RegExp("-", "gm"), "/")).getTime();