Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

257
Views
How to generate random longitude and latitude?

I need to generate some random longitude and latitude like 39.21988,9.124741.

I tried:

function getRandomInRange(from, to, fixed) {
    return (Math.random() * (to - from) + from).toFixed(fixed) * 1;
}
for(var i =0; i<4; i++) {
 console.log(getRandomInRange(-180, 180, 3));
}

But the result is:

-107.237
5.533
-118.927
90.629

While I'd need them comma separated every 2 so it should be:

-107.237,5.533
-118.927,90.629
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Hope this solve your issue:

function getRandomInRange(from, to, fixed) {
    return parseFloat((Math.random() * (to - from) + from).toFixed(fixed));
}

var latLongPairs = 4;

for(var i =0; i<latLongPairs; i++) {
 console.log(`${getRandomInRange(-180, 180, 3)}, ${getRandomInRange(-180, 180, 3)}`);
}

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!