I am trying to combine the OSM OpenLayers example with the results I got from query.wikidata.org , but it seems that I am doing the wrong transformation. What would be the right transformation of long and lat?
<html><body>
<div id="mapdiv"></div>
<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
<script>
map = new OpenLayers.Map("mapdiv");
map.addLayer(new OpenLayers.Layer.OSM());
var lonLat = new OpenLayers.LonLat( 40.228055555556, 27.242222222222 )
.transform(
new OpenLayers.Projection("EPSG:900913"), // 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>
</body></html>
The transformation is wrong: your lonLat variable is in EPSG:4326, so you should transform from EPSG:4326 to EPSG:900913
var lonLat = new OpenLayers.LonLat( 27.242222222222, 40.228055555556 )
.transform(
new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
map.getProjectionObject() // to Spherical Mercator Projection
);
When using Leaflet it is not necessary to make any transformation.
var map = L.map('map').setView(40.228055555556, 27.242222222222],
13);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
L.marker([40.228055555556, 27.242222222222]).addTo(map)
.bindPopup('A pretty CSS3 popup.<br> Easily customizable.')
.openPopup();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.