ReferenceError:openstreetmap中未定义OpenLayers

时间:2014-09-23 06:04:11

标签: javascript jquery openlayers

您好我正在尝试为openstreetstreetmap实施标记,并且它在firebug中显示错误ReferenceError: OpenLayers is not defined。这是我实施的代码:

<script>
    map = new OpenLayers.Map("map", {
        projection: "EPSG:900913",
        displayProjection: "EPSG:4326"
    });
    map.addLayer(new OpenLayers.Layer.OSM());
    var markers = new
    OpenLayers.Layer.Text("text", {location: "<?php echo $root_url; ?>"+"/marker_a.png", projection: map.displayProjection});
    map.addLayer(markers);
    map.zoomToMaxExtent();
</script>
<body>
    <iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://www.openstreetmap.org/export/embed.html?bbox=77.4471,12.8607,77.7664,13.0728&layer=mapnik" style="border: 1px solid black"></iframe>
    <br />
    <small>
        <a href="http://www.openstreetmap.org/?lat=12.96675&lon=77.60675&zoom=14&layers=M">View Larger Map</a>
    </small>
</body>

提前致谢。

1 个答案:

答案 0 :(得分:0)

<script>
image = "<?php echo $root_url; ?>" + "/marker_a.png";
var size = new OpenLayers.Size(21,25);
var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
var icon1 = new OpenLayers.Icon(image, size, offset);
var lonLat1 = new OpenLayers.LonLat(res[2],res[1]).transform( new `OpenLayers.Projection("EPSG:4326"), 
map.getProjectionObject());
var marker1 = new OpenLayers.Marker(lonLat1, icon1); 
marker1.icon.size = size; 
marker1.icon.offset = offset; 
markers.addMarker(marker1, icon1); 
</script>