使用tomtom SDK添加地图标记时出错

时间:2019-02-26 03:24:00

标签: javascript leaflet tomtom

传单库错误

每次尝试向地图添加地图标记时都会出现此错误

leaflet.js:5未捕获的TypeError:t.addLayer不是i.addTo(leaflet.js:5)的函数。此功能是库的一部分,我不知道为什么它不起作用。我的代码来自tomtom的开发人员门户。这是我的代码。

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel='stylesheet' type='text/css' href='sdk/map.css'/>
<link rel="stylesheet" href="style.css">
<script src='sdk/tomtom.min.js'></script>
<title>Document</title>
</head>
<body>
<header class="name-header">
    <div class="name-wrapper">
   <nav class="container">

   </nav>
</div>
</header>
<div class="img-wrapper">
    <div class="svgbox">

            </div>
       </div>

           <div id="map"> </div>


 <script>
     var storeLocation = [35.677512,-81.99855]

 const map =   tomtom.setProductInfo('KG\'s', '<your-product- 
 version>');
        tomtom.L.map("map", {
        key: 'myapikey',
                source: 'vector',
                center: storeLocation,
                basePath: '/sdk',
                zoom: 15


      });

   var marker = tomtom.L.marker(storeLocation).addTo(map);
   marker.bindPopup("my business").openPopup();

</script>
    </div>
</body>
</html>

我的css中声明了我的地图大小

2 个答案:

答案 0 :(得分:0)

您已将 map 分配给setProductInfo方法返回的内容。 应该将其分配给tomtom.L.map。

const map = tomtom.L.map("map", {
    key: 'myapikey',
    source: 'vector',
    center: storeLocation,
    basePath: '/sdk',
    zoom: 15
});

答案 1 :(得分:0)

您可以使用类似的内容:

const map = tomtom.L.map("map", {
    key: 'YOUR API KEY',
    center: [0.0000, 00.0000],
    basePath: 'tomtom',
    zoom: 16
});
var marker = tomtom.L.marker([0.0000, 00.0000]).addTo(map);
marker.bindPopup('Flyover International').openPopup();