Format numerical latitude and longitude in Javascript

Asked

Viewed 2,338 times

-1

I need to put the number of decimals in my latitude and longitude; currently they meet like this:

-50850080, -29361808

And I’d like it to stay that way:

-50.850080, -29.361808

Only it had to be something valid, because it can happen to have only 1 decimal place. I don’t know how to solve this or if it is possible.

  • 1

    Put in the relevant part of the code so we can see how you’re assembling the coordinate pair. Assuming they are numerical values, in principle it is only divided by 1000000, no?

  • Doing what you need is relatively easy, the problem is that the longitude goes from -180 to 180. If Voce has a number -179361808, it is a little complicated to know if it is -179.361808 or -17.9361808. If the houses after the point are always 6 there is quiet, but the accuracy may vary if I am not mistaken.

  • I think you need to give more details of the problem because it may not be a question of just putting the decimal point in the right place. Seems to be a coordinate conversion/projection problem.

1 answer

0

I will give a nephew and I will suggest a solution with plugin jQuery:

https://igorescobar.github.io/jQuery-Mask-Plugin/

In the block of examples, take a look at the functionality of "Translate". Adapting to the rules of longitude would look something like this:

$('input.longitude').mask('99Z.99999999', {
    translation: {
      'Z': {
        pattern: /[0-9]/,
        optional: true
      }
    }
});

Thus, if the user enters two digits and then the dot, the mask will not move the place point. But it is mandatory that the user enters the point.

The number of decimals is at the project’s discretion -- Google Maps uses 8 houses after the comma, but if I’m not mistaken, the longitude pattern can be up to 13 digits after the dot.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.