gpt4 book ai didi

javascript - 谷歌地图API : How to add my own markers to a map?

转载 作者:行者123 更新时间:2023-11-28 16:14:40 26 4
gpt4 key购买 nike

首先:英语不是我的语言,但我尝试:-)

我喜欢有一张带有标记的 map 。没有标记的 map 工作正常,你可以在这里看到它:map without markers

代码很简单:

<!DOCTYPE html>
<html>
<head>
<title>MyRange Driving Ranges world wide </title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=yes" />

<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 30px; padding: 0px }
#map_canvas { height: 80% }
</style>
<script type="text/javascript"
src="https://maps.google.com/maps/api/js?sensor=true">
</script>
<script type="text/javascript">
function initialize() {
var latlng = new google.maps.LatLng(51.1601369818597, 6.72036588191986);
var myOptions = {
zoom: 16,
center: latlng,
mapTypeId: google.maps.MapTypeId.HYBRID
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

//var image = 'http://myrange.de/support/images/flag_red_big.png';
//var myLatLng = new google.maps.LatLng(51.1601369818597, 6.72036588191986));
//var golfMarker = new google.maps.Marker({ position: myLatLng,map: map, icon: image });
}
</script>
</head>
<body onload="initialize()">
<div align="center" id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>

一切正常。如果我删除//就会得到一个空屏幕:-(这三行有什么问题?

var image = 'http://myrange.de/support/images/flag_red_big.png';
var myLatLng = new google.maps.LatLng(51.1601369818597, 6.72036588191986));
var golfMarker = new google.maps.Marker({ position: myLatLng,map: map, icon: image });

我希望你能听懂我的“英语”

来自德国的问候hape42

最佳答案

你的代码在行处中断

var myLatLng = new google.maps.LatLng(51.1601369818597, 6.72036588191986));

它有一个额外的右括号。改正它就会起作用。来自印度 friend 的问候..:)

关于javascript - 谷歌地图API : How to add my own markers to a map?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11845532/

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