代码:
<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
<script type="text/javascript">
map = new OpenLayers.Map("open_map");
map.addLayer(new OpenLayers.Layer.OSM());
var lonLat = new OpenLayers.LonLat( -0.1279688 ,51.5077286 )
.transform(
new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
map.getProjectionObject() // to Spherical Mercator Projection
);
var zoom=16;
var markers = new OpenLayers.Layer.Markers( "Markers" );
map.addLayer(markers);
markers.addMarker(new OpenLayers.Marker(lonLat));
map.setCenter (lonLat, zoom);
</script>
<div id="open_map" style="width:100%"></div>
我使用了官方网站示例,但它对我不起作用,它没有在浏览器中显示任何地图。
我在控制台中没有错误,奇怪......知道吗?
已编辑
<div id="open_map" style="width:100%;height:300px;position:relative;"></div>
<script type="text/javascript">
map = new OpenLayers.Map("open_map");
map.addLayer(new OpenLayers.Layer.OSM());
var lonLat = new OpenLayers.LonLat( -0.1279688 ,51.5077286 )
.transform(
new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
map.getProjectionObject() // to Spherical Mercator Projection
);
var zoom=16;
var markers = new OpenLayers.Layer.Markers( "Markers" );
map.addLayer(markers);
markers.addMarker(new OpenLayers.Marker(lonLat));
map.setCenter (lonLat, zoom);
</script>
现在我看到了在 div 元素之后移动脚本: