0

Hi I'm using Jquery's mouse position to find the position of the page.

I would like it to have it behave more like latitude and longitude coordinates.

    $().mousemove(function(e){
        $('#detect').html( e.pageX + '° N, '+ e.pageY + '° E' );

    });

I realise this is not true latitude and longitude coordinates. The box would be the webpage, and 0 is absolute middle of the webpage. Moving the mouse into the N/E area would produce this result.

NSEW

Any help would be appreciated. Thanks.

uriah
  • 2,485
  • 5
  • 28
  • 40

1 Answers1

2

Javascript:

var screenX = $(document).width() / 2;
var screenY = $(document).height() / 2;

$(document).mousemove(function(e){

    var apX = screenX - e.pageX;
    var apY = screenY - e.pageY;

    var latT = (apY>=0) ? 'N' : 'S';
    var lonT = (apX>=0) ? 'W' : 'E';

    apX = Math.round(Math.abs(apX));
    apY = Math.round(Math.abs(apY));

    $('#detect').html( apX  + 'px '+ latT +', '+ apY + 'px '+ lonT  );

});

You can find a test on http://jsfiddle.net/nvwzH/

user1040899
  • 534
  • 1
  • 8
  • 19
  • I think the coordinates are wrong but I think that was my initial mistake. http://jsfiddle.net/nvwzH/2/ Thanks for your help. – uriah Dec 14 '11 at 09:28