Using Proj4js with OpenLayers to transform lat lng from 4326 to 27700 but coming out unchangedUsing Proj4js in Openlayers - Proj4js is not definedOpenLayers/proj4js and the EPSG:27700 (UK) ProjectionOpenLayers transform EPSG 27700 coordinate to Google 900913Problems with features, popups and strategy with OpenLayersOpenLayers.Bounds transform not working as expectedGet Lat & Lng from GeoDjango OSMGeoAdminOpenlayers Transform not transforming a point from EPSG 27700 to EPSG 4326Using Proj4js in Openlayers - Proj4js is not definedUsing OSGB (ESPG: 27700) projection in Openlayers with MousePositionOpenLayers and proj4js.defs() - why does one custom projection work and not the other?Problem on changing the EPSG:3376 to EPSG:4326 using Proj4js

Why was this character made Grand Maester?

Python program to take in two strings and print the larger string

Freedom of Speech and Assembly in China

Why are GND pads often only connected by four traces?

Grade-school elementary algebra presented in an abstract-algebra style?

Where is Jon going?

Why is the Eisenstein ideal paper so great?

Why did other houses not demand this?

How to let other coworkers know that I don't share my coworker's political views?

How was Daenerys able to legitimise this character?

My players want to grind XP but we're using landmark advancement

Is my plasma cannon concept viable?

What is the view of Buddhism in correcting others' view in spite of their willingness to accept it?

Why didn't Thanos use the Time Stone to stop the Avengers' plan?

Non-containing subsets of two sizes

Writing style before Elements of Style

Which European Languages are not Indo-European?

Can I tell a prospective employee that everyone in the team is leaving?

How do I superimpose two math symbols?

Do photons bend spacetime or not?

Of strange atmospheres - the survivable but unbreathable

The disk image is 497GB smaller than the target device

How to deal with a colleague who is being aggressive?

Can you output map values in visualforce inline using a string key?



Using Proj4js with OpenLayers to transform lat lng from 4326 to 27700 but coming out unchanged


Using Proj4js in Openlayers - Proj4js is not definedOpenLayers/proj4js and the EPSG:27700 (UK) ProjectionOpenLayers transform EPSG 27700 coordinate to Google 900913Problems with features, popups and strategy with OpenLayersOpenLayers.Bounds transform not working as expectedGet Lat & Lng from GeoDjango OSMGeoAdminOpenlayers Transform not transforming a point from EPSG 27700 to EPSG 4326Using Proj4js in Openlayers - Proj4js is not definedUsing OSGB (ESPG: 27700) projection in Openlayers with MousePositionOpenLayers and proj4js.defs() - why does one custom projection work and not the other?Problem on changing the EPSG:3376 to EPSG:4326 using Proj4js






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















Using Proj4js to transform lat lng from 4326 to 27700 but coming out unchanged. I am using OpenLayers 2.12 (OS API Leisure map) EPSG 27700, Proj4js (CDN)



I have added the definition to proj4



epsg4326 = new OpenLayers.Projection("EPSG:4326"); //WGS 1984 projection 
// To
proj4.defs("EPSG:27700","+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs");
EPSG27700 = new OpenLayers.Projection("EPSG:27700");


var lonLat = new OpenLayers.LonLat(-0.1279688, 51.5077286).transform(epsg4326, EPSG27700);
console.log(lonLat);


lonLat is coming out as  lon: -0.1279688, lat: 51.5077286 so unchanged.



I think I'm missing a trick.










share|improve this question









New contributor



Simon Jeffs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    2















    Using Proj4js to transform lat lng from 4326 to 27700 but coming out unchanged. I am using OpenLayers 2.12 (OS API Leisure map) EPSG 27700, Proj4js (CDN)



    I have added the definition to proj4



    epsg4326 = new OpenLayers.Projection("EPSG:4326"); //WGS 1984 projection 
    // To
    proj4.defs("EPSG:27700","+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs");
    EPSG27700 = new OpenLayers.Projection("EPSG:27700");


    var lonLat = new OpenLayers.LonLat(-0.1279688, 51.5077286).transform(epsg4326, EPSG27700);
    console.log(lonLat);


    lonLat is coming out as  lon: -0.1279688, lat: 51.5077286 so unchanged.



    I think I'm missing a trick.










    share|improve this question









    New contributor



    Simon Jeffs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      2












      2








      2








      Using Proj4js to transform lat lng from 4326 to 27700 but coming out unchanged. I am using OpenLayers 2.12 (OS API Leisure map) EPSG 27700, Proj4js (CDN)



      I have added the definition to proj4



      epsg4326 = new OpenLayers.Projection("EPSG:4326"); //WGS 1984 projection 
      // To
      proj4.defs("EPSG:27700","+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs");
      EPSG27700 = new OpenLayers.Projection("EPSG:27700");


      var lonLat = new OpenLayers.LonLat(-0.1279688, 51.5077286).transform(epsg4326, EPSG27700);
      console.log(lonLat);


      lonLat is coming out as  lon: -0.1279688, lat: 51.5077286 so unchanged.



      I think I'm missing a trick.










      share|improve this question









      New contributor



      Simon Jeffs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      Using Proj4js to transform lat lng from 4326 to 27700 but coming out unchanged. I am using OpenLayers 2.12 (OS API Leisure map) EPSG 27700, Proj4js (CDN)



      I have added the definition to proj4



      epsg4326 = new OpenLayers.Projection("EPSG:4326"); //WGS 1984 projection 
      // To
      proj4.defs("EPSG:27700","+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs");
      EPSG27700 = new OpenLayers.Projection("EPSG:27700");


      var lonLat = new OpenLayers.LonLat(-0.1279688, 51.5077286).transform(epsg4326, EPSG27700);
      console.log(lonLat);


      lonLat is coming out as  lon: -0.1279688, lat: 51.5077286 so unchanged.



      I think I'm missing a trick.







      openlayers-2 proj4js






      share|improve this question









      New contributor



      Simon Jeffs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share|improve this question









      New contributor



      Simon Jeffs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share|improve this question




      share|improve this question








      edited 9 hours ago









      Ian Turton

      51.2k548120




      51.2k548120






      New contributor



      Simon Jeffs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      asked 9 hours ago









      Simon JeffsSimon Jeffs

      111




      111




      New contributor



      Simon Jeffs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      New contributor




      Simon Jeffs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          3 Answers
          3






          active

          oldest

          votes


















          2














          transform converts the point in place so no new point is returned. See the documentation:




          Transform the LonLat object from source to dest. This transformation is in place: if you want a new lonlat, use .clone() first.




          So you want something like:



           var lonLat = new OpenLayers.LonLat(-0.1279688, 51.5077286);
          lonLat.transform(epsg4326, EPSG27700);
          console.log(lonLat);





          share|improve this answer























          • The transformation is in place, but it still returns the result, for example in map.setCenter(new OpenLayers.LonLat(-0.1279688, 51.5077286).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject()));

            – Mike
            9 hours ago











          • Thanks for the tip, however both still output the original lat/lng

            – Simon Jeffs
            8 hours ago


















          1














          OpenLayers 2 uses an earlier proj4 (version 1.1.0) syntax:



          Proj4js.defs["EPSG:27700"] = "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs ";


          or with proj4 version 2:



          <!doctype html>
          <html lang="en">
          <head>
          <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.5.0/proj4.js"></script>
          <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/openlayers/2.12/OpenLayers.min.js"></script>
          </head>
          <body>
          <script type="text/javascript">

          window.Proj4js =
          Proj: function(code)
          return proj4(Proj4js.defs[code]);
          ,
          defs: proj4.defs,
          transform: proj4
          ;

          proj4.defs("EPSG:27700","+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs");

          var epsg4326 = new OpenLayers.Projection("EPSG:4326");
          var EPSG27700 = new OpenLayers.Projection("EPSG:27700");

          var lonLat = new OpenLayers.LonLat(-0.1279688, 51.5077286).transform(epsg4326, EPSG27700);
          alert(lonLat.lon + ' ' + lonLat.lat);

          </script>
          </body>
          </html>





          share|improve this answer

























          • If you are using the OS API some transforms are built in openspace.ordnancesurvey.co.uk/docs/4.0.0/files/OpenSpace/…

            – Mike
            9 hours ago











          • We were using the openspace api but are migrating to the OS API apidocs.os.uk/docs/os-maps-overview so have to remove the OpenSpace reference

            – Simon Jeffs
            9 hours ago











          • see also gis.stackexchange.com/questions/120021/…

            – Mike
            8 hours ago


















          0














          Ok, I figured out my issue. I looked at the post Mike shared Using Proj4js in Openlayers - Proj4js is not defined and tried the example code in my project which still failed. That narrowed it down to the js references. So I copied the references and et voila; success!



          My references:
          https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.5.0/proj4-src.js
          https://cdnjs.cloudflare.com/ajax/libs/openlayers/2.12/OpenLayers.min.js



          Changed to:
          https://cdnjs.cloudflare.com/ajax/libs/proj4js/1.1.0/proj4js-compressed.min.js
          https://cdnjs.cloudflare.com/ajax/libs/openlayers/2.13.1/OpenLayers.js



          Note that it worked with both versions of OpenLayers js file but not when using 2.5.0.



          Thanks to Ian and Mike for helping!






          share|improve this answer








          New contributor



          Simon Jeffs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.



















          • 2..5.0 is working for me. I've added the code to my answer.

            – Mike
            5 hours ago











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "79"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          Simon Jeffs is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f323552%2fusing-proj4js-with-openlayers-to-transform-lat-lng-from-4326-to-27700-but-coming%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          3 Answers
          3






          active

          oldest

          votes








          3 Answers
          3






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          transform converts the point in place so no new point is returned. See the documentation:




          Transform the LonLat object from source to dest. This transformation is in place: if you want a new lonlat, use .clone() first.




          So you want something like:



           var lonLat = new OpenLayers.LonLat(-0.1279688, 51.5077286);
          lonLat.transform(epsg4326, EPSG27700);
          console.log(lonLat);





          share|improve this answer























          • The transformation is in place, but it still returns the result, for example in map.setCenter(new OpenLayers.LonLat(-0.1279688, 51.5077286).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject()));

            – Mike
            9 hours ago











          • Thanks for the tip, however both still output the original lat/lng

            – Simon Jeffs
            8 hours ago















          2














          transform converts the point in place so no new point is returned. See the documentation:




          Transform the LonLat object from source to dest. This transformation is in place: if you want a new lonlat, use .clone() first.




          So you want something like:



           var lonLat = new OpenLayers.LonLat(-0.1279688, 51.5077286);
          lonLat.transform(epsg4326, EPSG27700);
          console.log(lonLat);





          share|improve this answer























          • The transformation is in place, but it still returns the result, for example in map.setCenter(new OpenLayers.LonLat(-0.1279688, 51.5077286).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject()));

            – Mike
            9 hours ago











          • Thanks for the tip, however both still output the original lat/lng

            – Simon Jeffs
            8 hours ago













          2












          2








          2







          transform converts the point in place so no new point is returned. See the documentation:




          Transform the LonLat object from source to dest. This transformation is in place: if you want a new lonlat, use .clone() first.




          So you want something like:



           var lonLat = new OpenLayers.LonLat(-0.1279688, 51.5077286);
          lonLat.transform(epsg4326, EPSG27700);
          console.log(lonLat);





          share|improve this answer













          transform converts the point in place so no new point is returned. See the documentation:




          Transform the LonLat object from source to dest. This transformation is in place: if you want a new lonlat, use .clone() first.




          So you want something like:



           var lonLat = new OpenLayers.LonLat(-0.1279688, 51.5077286);
          lonLat.transform(epsg4326, EPSG27700);
          console.log(lonLat);






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 9 hours ago









          Ian TurtonIan Turton

          51.2k548120




          51.2k548120












          • The transformation is in place, but it still returns the result, for example in map.setCenter(new OpenLayers.LonLat(-0.1279688, 51.5077286).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject()));

            – Mike
            9 hours ago











          • Thanks for the tip, however both still output the original lat/lng

            – Simon Jeffs
            8 hours ago

















          • The transformation is in place, but it still returns the result, for example in map.setCenter(new OpenLayers.LonLat(-0.1279688, 51.5077286).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject()));

            – Mike
            9 hours ago











          • Thanks for the tip, however both still output the original lat/lng

            – Simon Jeffs
            8 hours ago
















          The transformation is in place, but it still returns the result, for example in map.setCenter(new OpenLayers.LonLat(-0.1279688, 51.5077286).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject()));

          – Mike
          9 hours ago





          The transformation is in place, but it still returns the result, for example in map.setCenter(new OpenLayers.LonLat(-0.1279688, 51.5077286).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject()));

          – Mike
          9 hours ago













          Thanks for the tip, however both still output the original lat/lng

          – Simon Jeffs
          8 hours ago





          Thanks for the tip, however both still output the original lat/lng

          – Simon Jeffs
          8 hours ago













          1














          OpenLayers 2 uses an earlier proj4 (version 1.1.0) syntax:



          Proj4js.defs["EPSG:27700"] = "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs ";


          or with proj4 version 2:



          <!doctype html>
          <html lang="en">
          <head>
          <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.5.0/proj4.js"></script>
          <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/openlayers/2.12/OpenLayers.min.js"></script>
          </head>
          <body>
          <script type="text/javascript">

          window.Proj4js =
          Proj: function(code)
          return proj4(Proj4js.defs[code]);
          ,
          defs: proj4.defs,
          transform: proj4
          ;

          proj4.defs("EPSG:27700","+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs");

          var epsg4326 = new OpenLayers.Projection("EPSG:4326");
          var EPSG27700 = new OpenLayers.Projection("EPSG:27700");

          var lonLat = new OpenLayers.LonLat(-0.1279688, 51.5077286).transform(epsg4326, EPSG27700);
          alert(lonLat.lon + ' ' + lonLat.lat);

          </script>
          </body>
          </html>





          share|improve this answer

























          • If you are using the OS API some transforms are built in openspace.ordnancesurvey.co.uk/docs/4.0.0/files/OpenSpace/…

            – Mike
            9 hours ago











          • We were using the openspace api but are migrating to the OS API apidocs.os.uk/docs/os-maps-overview so have to remove the OpenSpace reference

            – Simon Jeffs
            9 hours ago











          • see also gis.stackexchange.com/questions/120021/…

            – Mike
            8 hours ago















          1














          OpenLayers 2 uses an earlier proj4 (version 1.1.0) syntax:



          Proj4js.defs["EPSG:27700"] = "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs ";


          or with proj4 version 2:



          <!doctype html>
          <html lang="en">
          <head>
          <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.5.0/proj4.js"></script>
          <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/openlayers/2.12/OpenLayers.min.js"></script>
          </head>
          <body>
          <script type="text/javascript">

          window.Proj4js =
          Proj: function(code)
          return proj4(Proj4js.defs[code]);
          ,
          defs: proj4.defs,
          transform: proj4
          ;

          proj4.defs("EPSG:27700","+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs");

          var epsg4326 = new OpenLayers.Projection("EPSG:4326");
          var EPSG27700 = new OpenLayers.Projection("EPSG:27700");

          var lonLat = new OpenLayers.LonLat(-0.1279688, 51.5077286).transform(epsg4326, EPSG27700);
          alert(lonLat.lon + ' ' + lonLat.lat);

          </script>
          </body>
          </html>





          share|improve this answer

























          • If you are using the OS API some transforms are built in openspace.ordnancesurvey.co.uk/docs/4.0.0/files/OpenSpace/…

            – Mike
            9 hours ago











          • We were using the openspace api but are migrating to the OS API apidocs.os.uk/docs/os-maps-overview so have to remove the OpenSpace reference

            – Simon Jeffs
            9 hours ago











          • see also gis.stackexchange.com/questions/120021/…

            – Mike
            8 hours ago













          1












          1








          1







          OpenLayers 2 uses an earlier proj4 (version 1.1.0) syntax:



          Proj4js.defs["EPSG:27700"] = "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs ";


          or with proj4 version 2:



          <!doctype html>
          <html lang="en">
          <head>
          <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.5.0/proj4.js"></script>
          <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/openlayers/2.12/OpenLayers.min.js"></script>
          </head>
          <body>
          <script type="text/javascript">

          window.Proj4js =
          Proj: function(code)
          return proj4(Proj4js.defs[code]);
          ,
          defs: proj4.defs,
          transform: proj4
          ;

          proj4.defs("EPSG:27700","+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs");

          var epsg4326 = new OpenLayers.Projection("EPSG:4326");
          var EPSG27700 = new OpenLayers.Projection("EPSG:27700");

          var lonLat = new OpenLayers.LonLat(-0.1279688, 51.5077286).transform(epsg4326, EPSG27700);
          alert(lonLat.lon + ' ' + lonLat.lat);

          </script>
          </body>
          </html>





          share|improve this answer















          OpenLayers 2 uses an earlier proj4 (version 1.1.0) syntax:



          Proj4js.defs["EPSG:27700"] = "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs ";


          or with proj4 version 2:



          <!doctype html>
          <html lang="en">
          <head>
          <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.5.0/proj4.js"></script>
          <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/openlayers/2.12/OpenLayers.min.js"></script>
          </head>
          <body>
          <script type="text/javascript">

          window.Proj4js =
          Proj: function(code)
          return proj4(Proj4js.defs[code]);
          ,
          defs: proj4.defs,
          transform: proj4
          ;

          proj4.defs("EPSG:27700","+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs");

          var epsg4326 = new OpenLayers.Projection("EPSG:4326");
          var EPSG27700 = new OpenLayers.Projection("EPSG:27700");

          var lonLat = new OpenLayers.LonLat(-0.1279688, 51.5077286).transform(epsg4326, EPSG27700);
          alert(lonLat.lon + ' ' + lonLat.lat);

          </script>
          </body>
          </html>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 5 hours ago

























          answered 9 hours ago









          MikeMike

          2,905139




          2,905139












          • If you are using the OS API some transforms are built in openspace.ordnancesurvey.co.uk/docs/4.0.0/files/OpenSpace/…

            – Mike
            9 hours ago











          • We were using the openspace api but are migrating to the OS API apidocs.os.uk/docs/os-maps-overview so have to remove the OpenSpace reference

            – Simon Jeffs
            9 hours ago











          • see also gis.stackexchange.com/questions/120021/…

            – Mike
            8 hours ago

















          • If you are using the OS API some transforms are built in openspace.ordnancesurvey.co.uk/docs/4.0.0/files/OpenSpace/…

            – Mike
            9 hours ago











          • We were using the openspace api but are migrating to the OS API apidocs.os.uk/docs/os-maps-overview so have to remove the OpenSpace reference

            – Simon Jeffs
            9 hours ago











          • see also gis.stackexchange.com/questions/120021/…

            – Mike
            8 hours ago
















          If you are using the OS API some transforms are built in openspace.ordnancesurvey.co.uk/docs/4.0.0/files/OpenSpace/…

          – Mike
          9 hours ago





          If you are using the OS API some transforms are built in openspace.ordnancesurvey.co.uk/docs/4.0.0/files/OpenSpace/…

          – Mike
          9 hours ago













          We were using the openspace api but are migrating to the OS API apidocs.os.uk/docs/os-maps-overview so have to remove the OpenSpace reference

          – Simon Jeffs
          9 hours ago





          We were using the openspace api but are migrating to the OS API apidocs.os.uk/docs/os-maps-overview so have to remove the OpenSpace reference

          – Simon Jeffs
          9 hours ago













          see also gis.stackexchange.com/questions/120021/…

          – Mike
          8 hours ago





          see also gis.stackexchange.com/questions/120021/…

          – Mike
          8 hours ago











          0














          Ok, I figured out my issue. I looked at the post Mike shared Using Proj4js in Openlayers - Proj4js is not defined and tried the example code in my project which still failed. That narrowed it down to the js references. So I copied the references and et voila; success!



          My references:
          https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.5.0/proj4-src.js
          https://cdnjs.cloudflare.com/ajax/libs/openlayers/2.12/OpenLayers.min.js



          Changed to:
          https://cdnjs.cloudflare.com/ajax/libs/proj4js/1.1.0/proj4js-compressed.min.js
          https://cdnjs.cloudflare.com/ajax/libs/openlayers/2.13.1/OpenLayers.js



          Note that it worked with both versions of OpenLayers js file but not when using 2.5.0.



          Thanks to Ian and Mike for helping!






          share|improve this answer








          New contributor



          Simon Jeffs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.



















          • 2..5.0 is working for me. I've added the code to my answer.

            – Mike
            5 hours ago















          0














          Ok, I figured out my issue. I looked at the post Mike shared Using Proj4js in Openlayers - Proj4js is not defined and tried the example code in my project which still failed. That narrowed it down to the js references. So I copied the references and et voila; success!



          My references:
          https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.5.0/proj4-src.js
          https://cdnjs.cloudflare.com/ajax/libs/openlayers/2.12/OpenLayers.min.js



          Changed to:
          https://cdnjs.cloudflare.com/ajax/libs/proj4js/1.1.0/proj4js-compressed.min.js
          https://cdnjs.cloudflare.com/ajax/libs/openlayers/2.13.1/OpenLayers.js



          Note that it worked with both versions of OpenLayers js file but not when using 2.5.0.



          Thanks to Ian and Mike for helping!






          share|improve this answer








          New contributor



          Simon Jeffs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.



















          • 2..5.0 is working for me. I've added the code to my answer.

            – Mike
            5 hours ago













          0












          0








          0







          Ok, I figured out my issue. I looked at the post Mike shared Using Proj4js in Openlayers - Proj4js is not defined and tried the example code in my project which still failed. That narrowed it down to the js references. So I copied the references and et voila; success!



          My references:
          https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.5.0/proj4-src.js
          https://cdnjs.cloudflare.com/ajax/libs/openlayers/2.12/OpenLayers.min.js



          Changed to:
          https://cdnjs.cloudflare.com/ajax/libs/proj4js/1.1.0/proj4js-compressed.min.js
          https://cdnjs.cloudflare.com/ajax/libs/openlayers/2.13.1/OpenLayers.js



          Note that it worked with both versions of OpenLayers js file but not when using 2.5.0.



          Thanks to Ian and Mike for helping!






          share|improve this answer








          New contributor



          Simon Jeffs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          Ok, I figured out my issue. I looked at the post Mike shared Using Proj4js in Openlayers - Proj4js is not defined and tried the example code in my project which still failed. That narrowed it down to the js references. So I copied the references and et voila; success!



          My references:
          https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.5.0/proj4-src.js
          https://cdnjs.cloudflare.com/ajax/libs/openlayers/2.12/OpenLayers.min.js



          Changed to:
          https://cdnjs.cloudflare.com/ajax/libs/proj4js/1.1.0/proj4js-compressed.min.js
          https://cdnjs.cloudflare.com/ajax/libs/openlayers/2.13.1/OpenLayers.js



          Note that it worked with both versions of OpenLayers js file but not when using 2.5.0.



          Thanks to Ian and Mike for helping!







          share|improve this answer








          New contributor



          Simon Jeffs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.








          share|improve this answer



          share|improve this answer






          New contributor



          Simon Jeffs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.








          answered 6 hours ago









          Simon JeffsSimon Jeffs

          111




          111




          New contributor



          Simon Jeffs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.




          New contributor




          Simon Jeffs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.














          • 2..5.0 is working for me. I've added the code to my answer.

            – Mike
            5 hours ago

















          • 2..5.0 is working for me. I've added the code to my answer.

            – Mike
            5 hours ago
















          2..5.0 is working for me. I've added the code to my answer.

          – Mike
          5 hours ago





          2..5.0 is working for me. I've added the code to my answer.

          – Mike
          5 hours ago










          Simon Jeffs is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          Simon Jeffs is a new contributor. Be nice, and check out our Code of Conduct.












          Simon Jeffs is a new contributor. Be nice, and check out our Code of Conduct.











          Simon Jeffs is a new contributor. Be nice, and check out our Code of Conduct.














          Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f323552%2fusing-proj4js-with-openlayers-to-transform-lat-lng-from-4326-to-27700-but-coming%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

          Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

          François Viète Contents Biography Work and thought Bibliography See also Notes Further reading External links Navigation menup. 21Google Bookspp. 75–77Google BooksDe thou (from University of Saint Andrews)ArchivedGoogle BooksGoogle BooksGoogle BooksGoogle booksGoogle Bookscc-parthenay.frL'histoire universelle (fr)Universal History (en)ArchivedAdsabs.harvard.eduPagesperso-orange.frArchive.orgChikara Sasaki. Descartes' mathematical thought p.259Google BooksGoogle BooksGoogle Bookspp. 152 and onwardGoogle BooksGoogle BooksScribd.comGoogle Books1257-7979Google BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGallica.bnf.frGoogle BooksGoogle Books"François Viète"Francois Viète: Father of Modern Algebraic NotationThe Lawyer and the GamblerAbout TarporleySite de Jean-Paul GuichardL'algèbre nouvelle"About the Harmonicon"cb120511976(data)1188044800000 0001 0913 5903n82164680ola2013766880073431702w6vt1sb70287374827140948071409480