Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

128
Vistas
How to generate a set of geospacial coordinates?

I tried using this:

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

That's ok for random numbers like 39.21988,9.124741 but they might end up not valid coordinates. And I need 100 of them.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Your latitude range is incorrect - it should be ±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 Denunciar

0

You might need to provide some initial Latitude and longitude with some radius (in meters)

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda