3 Replies - 1122 Views - Last Post: 09 March 2013 - 11:53 AM

#1 theplan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 21-February 13

UK Grid References to Lat/Lng

Posted 26 February 2013 - 04:37 PM

I am currently developing a web application with Google Maps that is allowing a community to make entries to a database and then be able to query the database to pull info relevant for them. The nature of entries means that more often than not, a user will want to specify their location as a grid reference on the National Grid, of differing digit lengths, but mainly 6-8. I also have a database of around 200 locations without latitude or longitude coordinates assigned to them, just Grid References of 6 digit lengths.

Data entry is done through an HTML form. Ideally, I would like a user to enter a grid reference in to the text field e.g SK828040 and for the latitude and longitude coordinates to appear in their respective text fields. Likewise, if a user enters latitude and longitude coordinates, then the grid ref field would be populated.

I have been looking at, and working to try and implement the script found here http://www.movable-t...ng-gridref.html by Chris Veness - But I'm having a little trouble with implementing it to update the form when a value has been entered.

I tried to get a better understanding by looking at the source code of the site above, but made me a little more confused!

Any nudges in the right direction would be great!!!

Thanks!!

Is This A Good Question/Topic? 0
  • +

Replies To: UK Grid References to Lat/Lng

#2 theplan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 21-February 13

Re: UK Grid References to Lat/Lng

Posted 03 March 2013 - 01:03 PM

bump (is bumping allowed?)
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3838
  • View blog
  • Posts: 13,592
  • Joined: 12-December 12

Re: UK Grid References to Lat/Lng

Posted 03 March 2013 - 02:44 PM

View Posttheplan, on 03 March 2013 - 01:03 PM, said:

bump (is bumping allowed?)

I assume bumping is allowed (after a reasonable interval!) but I'm not sure how we can help. If that script is causing you problems then you might search for an alternative script. If it is a particular problem with this script then post some relevant code, describing what you think the issue is.

If you haven't already, learn to use your browser's console to discover any error messages, and to test your code. There are links in my signature.
Was This Post Helpful? 0
  • +
  • -

#4 theplan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 21-February 13

Re: UK Grid References to Lat/Lng

Posted 09 March 2013 - 11:53 AM

Thanks for the reply.

I have the script working fine (I was just being silly) and I am now converting grid refs to lat long and vice versa. Now, what I am having trouble with is, instead of showing the Grid Ref to Lat Long result as "lat - 5239′28.7481″N long - 00142′57.7411″E" I would like them to be shown as their decimal counterparts "lat - 52.657985 long - 1.716039"

Now the scripts provided on the above website do use the numbers in it's functions. If you look at the functional demo on the page and follow the console outputs, the WGS84 Lat/Lon fields convert between the two, however only displays using degrees.

If anyone can give me an idea on how to get the decimal version of the lat long coordinates up I would be very grateful! The script that makes use of the coords in decimals is here (I think) - http://www.movable-t.../scripts/geo.js

The code for updating the fields (in the above demo):
$(document).ready(function() {
    prettyPrint();
    
    // wgs84 point updated
    $('#latWGS84,#lonWGS84').change( function() {
      var lat = Geo.parseDMS($('#latWGS84').val());
      var lon = Geo.parseDMS($('#lonWGS84').val());
      pWGS = new LatLon(lat, lon);
      console.log(pWGS); 
      pOSGB = CoordTransform.convertWGS84toOSGB36(pWGS);
      console.log(pOSGB);
      $('#latOSGB36').val(pOSGB.lat('dms',4)); 
      $('#lonOSGB36').val(pOSGB.lon('dms',4));
      var gridref = OsGridRef.latLongToOsGrid(pOSGB);
      $('#grid-ref').val(gridref.toString());
      $('#east-north').html(gridref.easting+','+gridref.northing);
    });
    
    // osgb36 point updated
    $('#latOSGB36,#lonOSGB36').change( function() {
      var lat = Geo.parseDMS($('#latOSGB36').val());
      var lon = Geo.parseDMS($('#lonOSGB36').val());
      pOSGB = new LatLon(lat, lon); 
      pWGS = CoordTransform.convertOSGB36toWGS84(pOSGB);
      $('#latWGS84').val(pWGS.lat('dms',4)); 
      $('#lonWGS84').val(pWGS.lon('dms',4));
      var gridref = OsGridRef.latLongToOsGrid(pOSGB);
      $('#grid-ref').val(gridref.toString());
      $('#east-north').html(gridref.easting+','+gridref.northing);
    });
    
    // os grid ref updated
    $('#grid-ref').change( function() {
      var gridref = OsGridRef.parse($('#grid-ref').val());
      var pOSGB = OsGridRef.osGridToLatLong(gridref); 
      var pWGS = CoordTransform.convertOSGB36toWGS84(pOSGB);
      $('#latWGS84').val(pWGS.lat('dms',4)); 
      $('#lonWGS84').val(pWGS.lon('dms',4));
      $('#latOSGB36').val(pOSGB.lat('dms',4)); 
      $('#lonOSGB36').val(pOSGB.lon('dms',4));
      $('#east-north').html(gridref.easting.padLz(6)+','+gridref.northing.padLz(6));
    });
  });


Is there a way to modify this bit of code to get my desired results?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1