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

127
Visualizações
Filter List of Citys by driving Distance

I'm not really new to HTML, Java and so on, but last time I coded is years ago.

I have the following list of German cities and I want to filter them by the driving distance in km. I only want to show cities that are closer than 75 km or exactly 75 km to my “main position”. I would do it manually, but this is not the only list I have to filter.

"Bad Eilsen, Buchholz, Hannover, Heeßen, Luhden, Samtgemeinde Lindhorst, Beckedorf, Heuerßen, Berlin, Lindhorst, Lüdersfeld, Samtgemeinde Nenndorf, Bad Nenndorf, Haste, Kassel, Hohnhorst, Suthfeld, Samtgemeinde Niedernwöhren, Lauenhagen, Meerbeck, Dortmund, Niedernwöhren, Nordsehl, Pollhagen, Wiedensahl, Samtgemeinde Nienstädt, Helpsen, Hespe, Frankfurt, Nienstädt, Freiburg, Seggebruch, Potsdam"

I thought about using the website "www.luftlinie.org" as my filter. When I give it two locations, it outputs the distance in km inside a span called "value". I started looking for the URL, which I can use to get the outputs when inserting city names. It is: "https://www.luftlinie.org/Hameln,Niedersachsen,DEU/"cityname",Niedersachsen,DEU/"

My challenges to do now:

  • Put the list of cities into variables.
  • Use the var to put them into the filter URL
  • Check if the span “value” is lower than 75 km or equal to 75 km.
  • If positive, display the name in a simple list, else do not display

Back in the day this would not be a problem for me, I used php and javascript jquery but today it is really hard to understand and all scripts I tried did not even show anything. Here is an example I tried it with....

<script>

$.get('https://www.luftlinie.org/Hameln,Niedersachsen,DEU/berlin,%20niedersachsen').then(function (html) {
    // Success response
    var $mainbar = $(html).find('#rt');
    document.write($mainbar.html());
}, function () {
    // Error response
    document.write('Access denied');
});
</script>

Would be great if someone could help me with that part, as I spent half of the day already on that...

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

0

You can't get webpages cross-domain using client-side code like jQuery - browsers won't allow it (see here for some background on same-origin policy). You'll either have to use a server-side solution in e.g. Node or Java, or access the data you want via an API.

It looks like they offer an API here that might suit your needs.

about 4 years ago · Juan Pablo Isaza Relatório

0

What Will Jenkins said is generally true, but I checked out the website itself, and the "API" link in the bottom right corner forwards to docs.distance.to/api. So instead of going through all that work of manually scraping another website, why not use the underlying API? Then the CORS issues should be solved, and it's much faster & efficient. Only disadvantage is that you need to register at Rapid API, IIRC they have a pretty generous free tier. Good luck!

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