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

121
Views
¿Cómo generar un conjunto de coordenadas geoespaciales?

Intenté usar esto:

 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)}`); }

Eso está bien para números aleatorios como 39.21988, 39.21988,9.124741 pero podrían terminar como coordenadas no válidas. Y necesito 100 de ellos.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Su rango de latitud es incorrecto; debería ser de ±90.

 function getRandomInRange(from, to) { return Math.random() * (to - from) + from; } const latLongPairs = 4; for (let i = 0; i < latLongPairs; ++i) { let lat = getRandomInRange(-90, 90); let lon = getRandomInRange(-180, 180); console.log(`${lat.toFixed(3)}, ${lon.toFixed(3)}`); }

about 4 years ago · Juan Pablo Isaza Report

0

Es posible que deba proporcionar una latitud y longitud iniciales con un radio (en metros)

 var getRandomLocation = function(latitude, longitude, radiusInMeters) { var getRandomCoordinates = function(radius, uniform) { // Generate two random numbers var a = Math.random(), b = Math.random(); // Flip for more uniformity. if (uniform) { if (b < a) { var c = b; b = a; a = c; } } // It's all triangles. return [ b * radius * Math.cos(2 * Math.PI * a / b), b * radius * Math.sin(2 * Math.PI * a / b) ]; }; var randomCoordinates = getRandomCoordinates(radiusInMeters, true); // Earths radius in meters via WGS 84 model. var earth = 6378137; // Offsets in meters. var northOffset = randomCoordinates[0], eastOffset = randomCoordinates[1]; // Offset coordinates in radians. var offsetLatitude = northOffset / earth, offsetLongitude = eastOffset / (earth * Math.cos(Math.PI * (latitude / 180))); return `${latitude + (offsetLatitude * (180 / Math.PI))}, ${longitude + (offsetLongitude * (180 / Math.PI))}` }; for (i = 0; i < 182; i++) { console.log(getRandomLocation(41.8819, -87.6278, 50)) }

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!