Openlayers OSM always set on (long/lat) (0/0)

this is my code

map = new OpenLayers.Map("map");    
// I tried several projections here, all lead to the same result
var proj = new OpenLayers.Projection("WGS84");
var point = new OpenLayers.LonLat(position.coords.latitude,position.coords.longitude);
point.transform(proj, map.getProjectionObject());

// the output of this shows the correct coordinates
console.log("latitude: "+position.coords.latitude+"  long "+position.coords.longitude);

var mapnik = new OpenLayers.Layer.OSM();

It always shows the map centered on coordinate (0/0) wich is somewhere in the atlantic ocean. Where is my error? I cant solve this and find nothing on google. Please help.

This, however, works.

map = new OpenLayers.Map( 'map');
layer = new OpenLayers.Layer.OSM( "Simple OSM Map");
  new OpenLayers.LonLat(position.coords.latitude,position.coords.longitude).transform(
  new OpenLayers.Projection("EPSG:4326"),
  ), 12


If you tried several projections and all lead to the same result that's probably because Proj4js is not correctly loaded (see

Check also this example: (coords re-projection from EPSG:4326)

Need Your Help

Accessing base user control properties from child user control

c# dynamic user-controls inheritance

My application has a custom base user control that is inherited from other user controls. This custom base user control has three properties that have been made public. When the user contro...

Nic Edit : Bullet point in not working

ruby-on-rails ruby-on-rails-3 nicedit

I have used ' Nic Edit ' in my rails project .

Need to store LOTS of data on Android device, thinking of going OODB

android sqlite oodbms oodb

I'm currently working on a project that's based on Android. Without getting into many details, the software will run on a custom built device. The hardware will never change and will always be the ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.