谷歌地图api:如何将我自己的标记添加到地图

Google map api : How to add my own markers to a map?

本文关键字:添加 地图 自己的 我自己 api 谷歌地图      更新时间:2023-09-26

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

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

代码很简单:

<!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>

一切正常。如果我删除//则会出现一个空屏幕:-(这3行有什么问题?

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 });

我希望你能理解我的"英语"

来自德国的问候哈普42

你的代码在行中断

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

它有一个额外的右括号。纠正它,它将起作用。来自印度伙伴的问候..:)