gpt4 book ai didi

html - 如何将 Google Earth KML 文件添加到 html iframe?

转载 作者:行者123 更新时间:2023-12-05 01:21:03 25 4
gpt4 key购买 nike

基本上,我正在尝试将我的 Google 地球 div 上的 KML 文件添加/显示到我的网站。我称我的文件为“satellites.kml”。

<!-- html code starts...-->

<p><iframe
name="myKMLEarth"
src="/getrack/satellites.kml"
height="440"
width="100%"
frameborder="0"
scrolling="no">
</iframe></p>

<!-- html code continues ...-->

当页面加载时,它会下载我的 KML 而不是在 iframe 中打开它。我不应该使用 src 链接到 KML 文件吗?任何意见,将不胜感激!提前致谢!

最佳答案

您必须使用 Google Maps JavaScript API https://developers.google.com/maps/documentation/javascript/reference?hl=es

您必须附上 google.maps.KmlLayer到 map 。

将 API 脚本放在 <head>

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=false"></script>

像这样创建一个 div:

<div id="google-map" class="google-map"></div>

然后,在</body>之前使用这段JS代码.将您的纬度、经度和路径设置为 KML 文件。

<script>
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(YOUR_LAT,YOUR_LNG), //Set your latitude, longitude
zoom: 19,
mapTypeId: google.maps.MapTypeId.SATELLITE,
scrollwheel: false
}

var map = new google.maps.Map(document.getElementById('google-map'), mapOptions); // get the div by id

var ctaLayer = new google.maps.KmlLayer({
url: 'PATH/TO/FILE.kml' // Set the KML file
});

// attach the layer to the map
ctaLayer.setMap(map);
}

// load the map
google.maps.event.addDomListener(window, 'load', initialize);
</script>

关于html - 如何将 Google Earth KML 文件添加到 html iframe?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26598625/

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