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

199
Visualizações
HERE Maps API outputting function results too many times

having some issues with the HERE maps api outputting the data i'm requesting too many times. I need it to output only once every 10 seconds, however it is doing it far more times than that.

The code I have here is as follows:

function getMapCorners() {
  var mapView = map.getViewModel();
  var mapCorners = mapView.b.bounds.cb.X;
  var corners = [mapCorners[9], mapCorners[10], mapCorners[3], mapCorners[4]];
  console.log(corners);
}
map.addEventListener("mapviewchange", function () {
  setTimeout(getMapCorners, 10000);
});

I need to grab these specific co-ordinates as this is feeding into another API that is creating markers on the map in specific areas. When zooming in, it does wait 10 seconds to run the function, but then it throws out the co-ordinate changes for every change in the map's view model during that 10 seconds.

The other API has a request limit of 100 every 15 minutes. So I need this to change so that it will run the function every 10 seconds, and it will only output the information for the final viewModel when the function runs.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

First, please don't use internal name of objects like .b.bounds.cb.X - b, cb, X are defined by compilation of js library and will be changed for new version of JS API. Please use for it a name of methods and objects described in documentation: https://developer.here.com/documentation/maps/3.1.29.0/api_reference/H.map.ViewModel.html#getLookAtData like:

var mapCorners = map.getViewModel().getLookAtData().bounds.getBoundingBox();

Second, the map event 'mapviewchange' runs multiply times during interacting with map therefore you get multiply times run of function getMapCorners. Suggestion to achieve what you want:

function getMapCorners() {
  console.log("getMapCorners!!!", map.getViewModel().getLookAtData().bounds.getBoundingBox());
  map.addEventListener("mapviewchange", onMapViewChange);
}

function onMapViewChange() {
    map.removeEventListener("mapviewchange", onMapViewChange);
    setTimeout(getMapCorners, 10000);
}

See please full code there on https://jsfiddle.net/1m8fvLjy/1/

about 4 years ago · Juan Pablo Isaza Relatório

0

If you want to run getMapCorners once every 10 seconds, then do this:

function doEveryTenSeconds(){
    getMapCorners();

    setTimeout(doEveryTenSeconds, 10000);
}

doEveryTenSeconds();
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