Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

122
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda