Sudhir Koimattur Sudhir Koimattur - 5 months ago 25
jQuery Question

ReferenceError: OpenLayers is not defined in openstreetmap

Hello I'm trying to implement a marker to the

openstreetstreetmap
and it is showing the error in firebug as
ReferenceError: OpenLayers is not defined
. Here is the code which I have implemented :

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


Thanks in advance.

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