【问题标题】:Google map api : How to add my own markers to a map?Google map api:如何将我自己的标记添加到地图中?
【发布时间】:2012-08-07 20:13:28
【问题描述】:

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

我喜欢有标记的地图。 没有标记的地图可以正常工作,你可以在这里看到: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>

一切正常。如果我删除 // 比我得到一个空屏幕:-( 这 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 });

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

来自德国的问候 hape42

【问题讨论】:

    标签: javascript google-maps-api-3 google-maps-markers


    【解决方案1】:

    你的代码在一行中断

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

    它有一个额外的右括号。纠正它,它会工作。 来自印度哥们的问候..:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-13
      • 2012-07-07
      • 2011-04-14
      • 2016-02-05
      • 2013-12-12
      • 1970-01-01
      • 1970-01-01
      • 2017-05-15
      相关资源
      最近更新 更多