I am trying to read an KML file (point feature) and show it on a vector layer on OSM as the base map. My code seems to have a problem that does not show the features on the map. I don't now if its the problem with reading the data from KML file or is it related to visualizing it by Openlayers. Any help would be appreciated... Thanks!
My code:
<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
<script>
function init() {
map = new OpenLayers.Map("map");
var mapnik = new OpenLayers.Layer.OSM();
var fromProjection = new OpenLayers.Projection("EPSG:4326"); // Transform from WGS 1984
var toProjection = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection
var position = new OpenLayers.LonLat(48.69,31.345).transform( fromProjection, toProjection);
var zoom = 12;
var layer = new OpenLayers.Layer.Vector("KML", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: "points.kml",
format: new OpenLayers.Format.KML()
})
});
map.addLayers([mapnik, layer]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.setCenter(position, zoom );
}
and my kml data:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
<name>Agencies test</name>
<Folder>
<name>BlahBlah!</name>
<Placemark id="2">
<name>Something here!</name>
<description>test</description>
<LookAt>
<longitude>49.69</longitude>
<latitude>32.345</latitude>
<altitude>0</altitude>
<range>24.63686803544318</range>
<tilt>0</tilt>
<heading>1.387289180270979e-005</heading>
</LookAt>
<Point>
<coordinates>49.69,32.345,0</coordinates>
</Point>
</Placemark>
</Folder>
</Document>
</kml>