Format numeric latitude and longitude in Javascript

-1

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

-50850080, -29361808

And I would like it to look like this:

-50.850080, -29.361808

It just had to be something valid, as it might happen to have only 1 decimal place. I do not know how to solve this or if it is possible.

    
asked by anonymous 22.08.2016 / 05:50

1 answer

0

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

link

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

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

In this way, if the user enters two digits and then the point, the mask will not move the place point. But it is mandatory for the user to enter the period.

The number of decimal places is at the discretion of the project - Google Maps uses 8 houses after the comma, but if I am not mistaken, the longitude pattern can be up to 13 digits after the point.

    
16.01.2017 / 16:04