gpt4 book ai didi

javascript - 如何在 html head 中编写正确的 HERE javascript 源代码?浏览器总是无法加载资源

转载 作者:可可西里 更新时间:2023-11-01 13:41:16 25 4
gpt4 key购买 nike

我只想创建一个默认网站,显示像 HEREMaps 中的演示这样的 map .已经提供了 HTML 和 JavaScript 代码,所以我只需要将两者放在一起就应该可以工作,但似乎有一个错误。

不幸的是,我的代码在所有浏览器中都失败了,因为在 HTML 头部中一些指向脚本资源的链接后面没有内容:

  • ../template.css
  • ../test-credentials.js
  • ../js-examples-rendering-helpers/iframe-height.js

这对我来说似乎很明显,但是 jsFiddle 可以毫无问题地读取这个文件,而且我很确定 HEREMaps 没有提供错误的代码,所以我想知道我的代码有什么问题。

出于安全原因,我不会写我的凭据,所以如果您尝试的话,必须替换 window.apikey

提前致谢!

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=yes">
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">

<title>Map at a specified location</title>
<link rel="stylesheet" type="text/css" href="https://js.api.here.com/v3/3.1/mapsjs-ui.css" />
<link rel="stylesheet" type="text/css" href="demo.css" />
<link rel="stylesheet" type="text/css" href="styles.css" />
<link rel="stylesheet" type="text/css" href="../template.css" />
<script type="text/javascript" src='../test-credentials.js'></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-core.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-service.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-ui.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-mapevents.js"></script>
<script type="text/javascript" src='../js-examples-rendering-helpers/iframe-height.js'></script>
</head>

<body id="markers-on-the-map">
<script type="text/javascript" src='demo.js'>

/**
* Moves the map to display over Berlin
*
* @param {H.Map} map A HERE Map instance within the application
*/

function moveMapToBerlin(map){
map.setCenter({lat:52.5159, lng:13.3777});
map.setZoom(14);
}

/**
* Boilerplate map initialization code starts below:
*/

//Step 1: initialize communication with the platform
// In your own code, replace variable window.apikey with your own apikey
var platform = new H.service.Platform({
apikey: window.apikey
});
var defaultLayers = platform.createDefaultLayers();

//Step 2: initialize a map - this map is centered over Europe
var map = new H.Map(document.getElementById('map'),
defaultLayers.vector.normal.map,{
center: {lat:50, lng:5},
zoom: 4,
pixelRatio: window.devicePixelRatio || 1
});
// add a resize listener to make sure that the map occupies the whole container
window.addEventListener('resize', () => map.getViewPort().resize());

//Step 3: make the map interactive
// MapEvents enables the event system
// Behavior implements default interactions for pan/zoom (also on mobile touch environments)
var behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map));

// Create the default UI components
var ui = H.ui.UI.createDefault(map, defaultLayers);

// Now use the map as required...
window.onload = function () {
moveMapToBerlin(map);
}

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

最佳答案

点击您提供的链接。我已经建立了一个工作示例:

// HEREMaps - Demo API Key. You should change this.
var apikey = 'H6XyiCT0w1t9GgTjqhRXxDMrVj9h78ya3NuxlwM7XUs';

/**
* Moves the map to display over Berlin
*
* @param {H.Map} map A HERE Map instance within the application
*/
function moveMapToBerlin(map) {
map.setCenter({
lat: 52.5159,
lng: 13.3777
});
map.setZoom(14);
}

/**
* Boilerplate map initialization code starts below:
*/

//Step 1: initialize communication with the platform
// In your own code, replace variable window.apikey with your own apikey
var platform = new H.service.Platform({
apikey: apikey
});
var defaultLayers = platform.createDefaultLayers();

//Step 2: initialize a map - this map is centered over Europe
var map = new H.Map(document.getElementById('map'),
defaultLayers.vector.normal.map, {
center: {
lat: 50,
lng: 5
},
zoom: 4,
pixelRatio: window.devicePixelRatio || 1
});
// add a resize listener to make sure that the map occupies the whole container
window.addEventListener('resize', () => map.getViewPort().resize());

//Step 3: make the map interactive
// MapEvents enables the event system
// Behavior implements default interactions for pan/zoom (also on mobile touch environments)
var behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map));

// Create the default UI components
var ui = H.ui.UI.createDefault(map, defaultLayers);

// Now use the map as required...
window.onload = function() {
moveMapToBerlin(map);
}
#map {
width: 95%;
height: 450px;
background: grey;
}

#panel {
width: 100%;
height: 400px;
}
<link rel="stylesheet" type="text/css" href="https://js.api.here.com/v3/3.1/mapsjs-ui.css" />
<script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-core.js" charset="utf-8"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-service.js" charset="utf-8"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-ui.js" charset="utf-8"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-mapevents.js" charset="utf-8"></script>

<!-- Map Container -->
<div id="map"></div>

关于javascript - 如何在 html head 中编写正确的 HERE javascript 源代码?浏览器总是无法加载资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57777272/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com