I use openlayers 2.12.

I created a form where the user can insert a bounding box, to insert to the database a new borough.

To check the EPSG of the borough I tried the following

//ba bb bc bd came from the form
var thisIsNew=new OpenLayers.Bounds(ba, bb,bc, bd).getProjection();
alert (thisIsNew);

and also

var thisIsNew=new OpenLayers.Bounds(ba, bb,bc, bd);
var newest = thisIsNew.getProjection();

I never get an alert and on the console I see that "the object does not support that method", for both of the above ways.

What am I missing?

Thanks in advance


getProjection() method normally works with openlayers map object not with bounds and thats the reason you are getting "the object does not support that method" in console window.

Secondly to validate coordinates for EPSG:4326 (range between -180 to 180 and -90 to 90) you can simply javascript code to verify user input.

var x1 = ba; //input value from user

var y1 = bb; //input value from user

var x2 = bc; //input value from user

var y2 = bd; //input value from user

valid_x1 = false;

valid_x2 = false;

valid_y1 = false;

valid_y2 = false;

if (x1 >= -180 && x1 <= 180) {

    valid_x1 = true;

if (x2 >= -180 && x2 <= 180) {

    valid_x2 = true;


if (y1 >= -90 && y1 <= 90) {

    valid_y1 = true;


if (y2 >= -90 && y2 <= 90) {

    valid_y2 = true;


if (valid_x1 && valid_x2 && valid_y1 && valid_y2) {

    console.log("Correct Projection");

} else {

    console.log("Wrong projection, insert only EPSG4326");
  • Ok. Any suggestions, on how to actually get the EPSG? – slevin Oct 18 '13 at 22:33
  • Can you share code? so i can have a look and get back to you but anyways I have updated the answer. – Farhat Abbas Oct 18 '13 at 22:44
  • Thanks, but I dont wont to transform to another projection. I just wont to get the current projection and if is not 4326 show a message to the user "Wrong projection, insert only EPSG4326". If it is EPSG4326 then the form will be submited ... – slevin Oct 18 '13 at 22:50
  • so it means you just want to validate user input whether x1,y1,x2,y2 are within EPSG:4326 range? – Farhat Abbas Oct 18 '13 at 22:53
  • Yes, this is what I want to do – slevin Oct 18 '13 at 22:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.