我正在尝试使用Google Maps API设置一个简单的页面,以便在位置上显示标记。不过我不是这个代码,这是基于谷歌的示例代码获取标记在这里。我将来源从
"https://maps.googleapis.com/maps/api/js?key=API_KEY&sensor=false"
到
"http://maps.google.com/maps/api/js?sensor=false"
因为这里推荐这样做是为了避免使用API密钥。var标记声明是从google这里复制的。要显示我的标记,必须改变什么?
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map-canvas { height: 100% }
</style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
</script>
<script type="text/javascript">
function initialize() {
var location = new google.maps.LatLng(59.272, 10.418);
var mapOptions = {
center: location,
zoom: 8
};
var marker = new google.maps.Marker({
position: location,
map: map,
title: 'Hello World!'
});
var map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"/>
</body>
</html>
将设置地图的线移到设置标记的线之前,因为标记在调用时会使用地图:
function initialize() {
var location = new google.maps.LatLng(59.272, 10.418);
var mapOptions = {
center: location,
zoom: 8
};
var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
var marker = new google.maps.Marker({
position: location,
map: map,
title: 'Hello World!'
});
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句