Section courante

A propos

Section administrative du site

 Langage  Elément  Programmation  Cadre d'application  Gabarit  UI  Extension  Projet  IDE  Langage  Outils  Annexe  Aide 
ABAP/4
Ada
Assembleur
Assembly & bytecode
ASP (Active Server Pages)
Basic
C
C++
C# (C Sharp)
Cobol
ColdFusion
Fortran
HTML
Java
JavaScript
LISP
Logo
LotusScript
Oberon
Pascal
Perl
PHP
PL/1
Prolog
Python
Rebol
REXX
Ruby
Rust
SAS
NoSQL
SQL
Swift
X++ (Axapta)
GNAT
SMALLAda
VHDL
Assembleur 370
Assembleur 1802
Assembleur 4004
Assembleur 6502
Assembleur 6800
Assembleur 68000
Assembleur 8080 et 8085
Assembleur 8089
Assembleur 80x86
Assembleur AGC4
Assembleur ARM
Assembleur DPS 8000
Assembleur i860
Assembleur Itanium
Assembleur MIPS
Assembleur PDP-11
Assembleur PowerPC
Assembleur RISC-V
Assembleur SPARC
Assembleur SuperH
Assembleur UNIVAC I
Assembleur VAX
Assembleur Z80
Assembleur Z8000
Assembleur z/Architecture
ASSEMBLER/MONITOR 64
Micol Assembler
GFA Assembler
A86
MASM (Macro Assembler)
TASM (Turbo Assembler)
CIL
Jasmin
LLVM
MSIL
Parrot
P-Code (PCode)
SWEET16
G-Pascal
ASP 1.0
ASP 2.0
ASP 3.0
ASP.NET
ASP.NET Core
ABasiC (Amiga)
Adam SmartBASIC
Altair BASIC
AmigaBASIC (Amiga)
AMOS Basic (Amiga)
Atari Basic (Atari 400, 600 XL, 800, 800XL)
Basic Apple II (Integer BASIC/APPLESOFT)
Basic Commodore 64 (CBM-BASIC)
Basic Commodore 128 (BASIC 7.0)
Basic Commodore VIC-20 (CBM-BASIC 2.0)
Basic Coco 1 (Color Basic)
Basic Coco 2 (Extended Color Basic)
Basic Coco 3 (Extended Color Basic 2.0)
BASICA (PC DOS)
Basic Pro
BBC BASIC
Blitz BASIC (Amiga)
DarkBASIC
Dartmouth BASIC
GFA-Basic (Atari ST/Amiga)
GWBASIC (MS-DOS)
Liberty BASIC
Locomotive BASIC (Amstrad CPC)
MSX-Basic
Omikron Basic (Atari ST)
Oric Extended Basic
Power Basic
Quick Basic/QBasic (MS-DOS)
Sinclair BASIC (ZX80, ZX81, ZX Spectrum)
ST BASIC (Atari ST)
Turbo Basic
Vintage BASIC
VBScript
Visual Basic (VB)
Visual Basic .NET (VB .NET)
Visual Basic pour DOS
Yabasic
BeckerBASIC
SIMONS' BASIC
Basic09 d'OS-9
Disk Extended Color Basic
Basic09 d'OS-9
Disk Extended Color Basic
Access
Excel
Visual Basic pour Windows
Visual Basic .NET pour Windows
C Shell Unix (csh)
C pour Amiga
C pour Atari ST
C pour DOS
C pour Falcon030
C pour GEMDOS (Atari ST)
C pour Linux
C pour PowerTV OS
C pour OS/2
C pour Unix
C pour Windows
Aztec C
CoCo-C
GNU C
HiSoft C
IBM C/2
Introl-C
Lattice C
Microsoft C
MinGW C
MSX-C
Open Watcom C
OS-9 C Compiler
Pure C
Quick C
Turbo C
HiSoft C for Atari ST
HiSoft C for CP/M (Amstrad CPC)
C++ pour OS/2
C++ pour Windows
Borland C++
C++Builder
IBM VisualAge C++
Intel C++
MinGW C++
Open Watcom C++
Symantec C++
Turbo C++
Visual C++
Visual C++ .NET
Watcom C++
Zortech C++
C# (C Sharp) pour Windows
Apple III Cobol
Microsoft Cobol
BlueDragon
Lucee
OpenBD
Railo
Smith Project
Microsoft Fortran
WATFOR-77
CSS
FBML
Open Graph
SVG
XML
XSL/XSLT
LESS
SASS
GCJ (GNU)
JSP
Jython
Visual J++
Node.js
TypeScript
AutoLISP
ACSLogo
LotusScript pour Windows
Amiga Oberon
Oberon .NET
Apple Pascal
Delphi/Kylix/Lazarus
Free Pascal
GNU Pascal
HighSpeed Pascal
IBM Personal Computer Pascal
Lisa Pascal
Maxon Pascal
MPW Pascal
OS-9 Pascal
OSS Personal Pascal
Pascal-86
Pascal du Cray Research
Pascal/VS
Pascal-XT
PURE Pascal
QuickPascal
RemObjets Chrome
Sun Pascal
THINK Pascal
Tiny Pascal (TRS-80)
Turbo Pascal
UCSD Pascal
VAX Pascal
Virtual Pascal
Turbo Pascal for CP/M-80
Turbo Pascal for DOS
Turbo Pascal for Macintosh
Turbo Pascal for Windows
CodeIgniter (Cadre d'application)
Drupal (Projet)
Joomla! (Projet)
Phalanger (PHP .NET)
phpBB (Projet)
Smarty (balise)
Twig (balise)
Symfony (Cadre d'application)
WordPress (Projet)
Zend (Cadre d'application)
PL360
PL/M-80
PL/M-86
Turbo Prolog
CPython
IronPython
Jython
PyPy
AREXX
Regina REXX
JMP
Btrieve
Cassandra
Clipper
CouchDB
dBASE
Hbase
Hypertable
MongoDB
Redis
Access
BigQuery
DB2
H2
Interbase
MySQL
Oracle
PostgreSQL
SAP HANA
SQL Server
Sybase
U-SQL
Introduction
Balises de ASP.NET
Les remarques
Les opérateurs
Les instructions conditionnelles
Les instructions de boucles
Les type de données
Variables
Directives de page
Versus
Bonjour
Formulaire
Géographie
Géométrie
Mathématique
Météorologie
Sport
Téléverser YouTube
Distance en Km entre deux longitudes et latitudes
Aire d'un cercle
Aire d'une surface de prisme rectangulaire
Aire d'un triangle
Distance entre deux points
Ackermann
Exp
Factoriel
Fibonacci
Log
Nombre premier
Odd
Random
Sqrt
Triangle Pascal
Unité de mesure
Hockey
.NET
ASP.NET MVC Framework
Entity Framework
Razor
Telerik UI pour ASP.NET AJAX
PdfViewer.dll
Umbraco
Visual Studio
C#
VB.NET
CFF Explorer
IL DASM
.NET Reflector
Vocabulaire
Fichiers spéciaux
Bibliographie
Web.config
.resx
Préface
Notes légal
Dictionnaire
Recherche

Une des fonctions les plus communes de la géographie et des systèmes modernes, c'est le calcul de la distance géographique entre deux coordonnées de Longitude et de Latitude. Il n'y a aucune nécessité de grande connaissance en trigonométrie pour arriver à se genre de calcul dans le format qu'on le souhaite, Km, Miles ou Miles Nautiques. Ainsi, si vous savez les coordonnées suivantes :

Ville Latitude Longitude
Montréal 45 31N 73 34O
Paris 48 50N 2 20E

A l'aide du code source ASP.NET (VB.NET) suivant, vous trouvez la réponse que vous souhaitez :

  1. <%@ Page Language="VB" %>
  2. <script runat="server">
  3.     Function CoordToDeltaKm( _
  4.      Q1Latitude As Double, Q1LatiDeg As Double, Q1LatiDirection As Char, _
  5.      Q1Longitude As Double, Q1LongDeg As Double, Q1LongDirection As Char, _
  6.      Q2Latitude As Double, Q2LatiDeg As Double, Q2LatiDirection As Char, _
  7.      Q2Longitude As Double, Q2LongDeg As Double, Q2LongDirection As Char) As Double
  8.         Dim a1, b1, a2, b2, RawDelta As Double
  9.         a1 = (Q1Latitude + (Q1LatiDeg / 60)) * Math.PI / 180
  10.         If Q1LatiDirection = "N" Then
  11.             a1 = -a1
  12.         End If
  13.         b1 = (Q1Longitude + (Q1LongDeg / 60)) * Math.PI / 180
  14.         If Q1LongDirection = "O" Then
  15.             b1 = -b1
  16.         End If
  17.         a2 = (Q2Latitude + (Q2LatiDeg / 60)) * Math.PI / 180
  18.         If Q2LatiDirection = "N" Then
  19.             a2 = -a2
  20.         End If
  21.         b2 = (Q2Longitude + (Q2LongDeg / 60)) * Math.PI / 180
  22.         If Q2LongDirection = "O" Then
  23.             b2 = -b2
  24.         End If
  25.         RawDelta = Math.Acos(Math.Cos(a1) * Math.Cos(b1) * Math.Cos(a2) * Math.Cos(b2) + Math.Cos(a1) * Math.Sin(b1) * Math.Cos(a2) * Math.Sin(b2) + Math.Sin(a1) * Math.Sin(a2))
  26.         CoordToDeltaKm = RawDelta * 6378.0
  27.     End Function
  28.  
  29.     Function CoordToDeltaStatuteMiles( _
  30.      Q1Latitude As Double, Q1LatiDeg As Double, Q1LatiDirection As Char, _
  31.      Q1Longitude As Double, Q1LongDeg As Double, Q1LongDirection As Char, _
  32.      Q2Latitude As Double, Q2LatiDeg As Double, Q2LatiDirection As Char, _
  33.      Q2Longitude As Double, Q2LongDeg As Double, Q2LongDirection As Char) As Double
  34.         Dim a1, b1, a2, b2, RawDelta As Double
  35.         a1 = (Q1Latitude + (Q1LatiDeg / 60)) * Math.PI / 180
  36.         If Q1LatiDirection = "N" Then
  37.             a1 = -a1
  38.         End If
  39.         b1 = (Q1Longitude + (Q1LongDeg / 60)) * Math.PI / 180
  40.         If Q1LongDirection = "O" Then
  41.             b1 = -b1
  42.         End If
  43.         a2 = (Q2Latitude + (Q2LatiDeg / 60)) * Math.PI / 180
  44.         If Q2LatiDirection = "N" Then
  45.             a2 = -a2
  46.         End If
  47.         b2 = (Q2Longitude + (Q2LongDeg / 60)) * Math.PI / 180
  48.         If Q2LongDirection = "O" Then
  49.             b2 = -b2
  50.         End If
  51.         RawDelta = Math.Acos(Math.Cos(a1) * Math.Cos(b1) * Math.Cos(a2) * Math.Cos(b2) + Math.Cos(a1) * Math.Sin(b1) * Math.Cos(a2) * Math.Sin(b2) + Math.Sin(a1) * Math.Sin(a2))
  52.         CoordToDeltaStatuteMiles = RawDelta * 3963.1
  53.     End Function
  54.  
  55.  
  56.     Function CoordToDeltaNauticalMiles( _
  57.      Q1Latitude As Double, Q1LatiDeg As Double, Q1LatiDirection As Char, _
  58.      Q1Longitude As Double, Q1LongDeg As Double, Q1LongDirection As Char, _
  59.      Q2Latitude As Double, Q2LatiDeg As Double, Q2LatiDirection As Char, _
  60.      Q2Longitude As Double, Q2LongDeg As Double, Q2LongDirection As Char) As Double
  61.         Dim a1, b1, a2, b2, RawDelta As Double
  62.         a1 = (Q1Latitude + (Q1LatiDeg / 60)) * Math.PI / 180
  63.         If Q1LatiDirection = "N" Then
  64.             a1 = -a1
  65.         End If
  66.         b1 = (Q1Longitude + (Q1LongDeg / 60)) * Math.PI / 180
  67.         If Q1LongDirection = "O" Then
  68.             b1 = -b1
  69.         End If
  70.         a2 = (Q2Latitude + (Q2LatiDeg / 60)) * Math.PI / 180
  71.         If Q2LatiDirection = "N" Then
  72.             a2 = -a2
  73.         End If
  74.         b2 = (Q2Longitude + (Q2LongDeg / 60)) * Math.PI / 180
  75.         If Q2LongDirection = "O" Then
  76.             b2 = -b2
  77.         End If
  78.         RawDelta = Math.Acos(Math.Cos(a1) * Math.Cos(b1) * Math.Cos(a2) * Math.Cos(b2) + Math.Cos(a1) * Math.Sin(b1) * Math.Cos(a2) * Math.Sin(b2) + Math.Sin(a1) * Math.Sin(a2))
  79.         CoordToDeltaNauticalMiles = RawDelta * 3443.9
  80.     End Function
  81. </script>
  82. <%
  83. Response.Write("Distance entre Montréal et Paris en Km: " &CStr(CoordToDeltaKm(45, 31,"N",73, 34,"O",48, 50,"N", 2,  20,"E")) &"<BR>")
  84. Response.Write("Distance entre Montréal et Paris en Miles: " &CStr(CoordToDeltaStatuteMiles(45, 31,"N", 73, 34,"O",    48, 50,"N", 2,  20,"E")) &"<BR>")
  85. Response.Write("Distance entre Montréal et Paris en Miles Nautique: " &CStr(CoordToDeltaNauticalMiles(45, 31,"N", 73, 34,"O",    48, 50,"N", 2,  20,"E")) &"<BR>")
  86. %>

ou en version ASP.NET (C# (C Sharp)) :

  1. <%@ Page Language="C#" %>
  2. <script runat="server">
  3.          static double CoordToDeltaKm(
  4.         double Q1Latitude, double Q1LatiDeg, char Q1LatiDirection,
  5.         double Q1Longitude, double Q1LongDeg, char Q1LongDirection,
  6.         double Q2Latitude, double Q2LatiDeg, char Q2LatiDirection,
  7.         double Q2Longitude, double Q2LongDeg, char Q2LongDirection
  8.     )
  9.         {
  10.             double a1, b1, a2, b2, RawDelta;
  11.             a1 = (Q1Latitude + (Q1LatiDeg / 60)) * Math.PI / 180;
  12.             if (Q1LatiDirection == 'N') a1 = -a1;
  13.             b1 = (Q1Longitude + (Q1LongDeg / 60)) * Math.PI / 180;
  14.             if (Q1LongDirection == 'O') b1 = -b1;
  15.             a2 = (Q2Latitude + (Q2LatiDeg / 60)) * Math.PI / 180;
  16.             if (Q2LatiDirection == 'N') a2 = -a2;
  17.             b2 = (Q2Longitude + (Q2LongDeg / 60)) * Math.PI / 180;
  18.             if (Q2LongDirection == 'O') b2 = -b2;
  19.             RawDelta = Math.Acos(Math.Cos(a1) * Math.Cos(b1) * Math.Cos(a2) * Math.Cos(b2) + Math.Cos(a1) * Math.Sin(b1) * Math.Cos(a2) * Math.Sin(b2) + Math.Sin(a1) * Math.Sin(a2));
  20.             return RawDelta * 6378.0;
  21.         }
  22.  
  23.         static double CoordToDeltaStatuteMiles(
  24.             double Q1Latitude, double Q1LatiDeg, char Q1LatiDirection,
  25.             double Q1Longitude, double Q1LongDeg, char Q1LongDirection,
  26.             double Q2Latitude, double Q2LatiDeg, char Q2LatiDirection,
  27.             double Q2Longitude, double Q2LongDeg, char Q2LongDirection
  28.         )
  29.         {
  30.             double a1, b1, a2, b2, RawDelta;
  31.             a1 = (Q1Latitude + (Q1LatiDeg / 60)) * Math.PI / 180;
  32.             if (Q1LatiDirection == 'N') a1 = -a1;
  33.             b1 = (Q1Longitude + (Q1LongDeg / 60)) * Math.PI / 180;
  34.             if (Q1LongDirection == 'O') b1 = -b1;
  35.             a2 = (Q2Latitude + (Q2LatiDeg / 60)) * Math.PI / 180;
  36.             if (Q2LatiDirection == 'N') a2 = -a2;
  37.             b2 = (Q2Longitude + (Q2LongDeg / 60)) * Math.PI / 180;
  38.             if (Q2LongDirection == 'O') b2 = -b2;
  39.             RawDelta = Math.Acos(Math.Cos(a1) * Math.Cos(b1) * Math.Cos(a2) * Math.Cos(b2) + Math.Cos(a1) * Math.Sin(b1) * Math.Cos(a2) * Math.Sin(b2) + Math.Sin(a1) * Math.Sin(a2));
  40.             return RawDelta * 3963.1;
  41.         }
  42.  
  43.         static double CoordToDeltaNauticalMiles(
  44.             double Q1Latitude, double Q1LatiDeg, char Q1LatiDirection,
  45.             double Q1Longitude, double Q1LongDeg, char Q1LongDirection,
  46.             double Q2Latitude, double Q2LatiDeg, char Q2LatiDirection,
  47.             double Q2Longitude, double Q2LongDeg, char Q2LongDirection
  48.         )
  49.         {
  50.             double a1, b1, a2, b2, RawDelta;
  51.             a1 = (Q1Latitude + (Q1LatiDeg / 60)) * Math.PI / 180;
  52.             if (Q1LatiDirection == 'N') a1 = -a1;
  53.             b1 = (Q1Longitude + (Q1LongDeg / 60)) * Math.PI / 180;
  54.             if (Q1LongDirection == 'O') b1 = -b1;
  55.             a2 = (Q2Latitude + (Q2LatiDeg / 60)) * Math.PI / 180;
  56.             if (Q2LatiDirection == 'N') a2 = -a2;
  57.             b2 = (Q2Longitude + (Q2LongDeg / 60)) * Math.PI / 180;
  58.             if (Q2LongDirection == 'O') b2 = -b2;
  59.             RawDelta = Math.Acos(Math.Cos(a1) * Math.Cos(b1) * Math.Cos(a2) * Math.Cos(b2) + Math.Cos(a1) * Math.Sin(b1) * Math.Cos(a2) * Math.Sin(b2) + Math.Sin(a1) * Math.Sin(a2));
  60.             return RawDelta * 3443.9;
  61.         } 
  62. </script>
  63. <%
  64. Response.Write("Distance entre Montréal et Paris en Km: " + CoordToDeltaKm(45, 31,'N',73, 34,'O',48, 50,'N', 2,  20,'E') + "<BR>");
  65. Response.Write("Distance entre Montréal et Paris en Miles: " + CoordToDeltaStatuteMiles(45, 31,'N', 73, 34,'O',    48, 50,'N', 2,  20,'E') + "<BR>");
  66. Response.Write("Distance entre Montréal et Paris en Miles Nautique: " + CoordToDeltaNauticalMiles(45, 31,'N', 73, 34,'O',    48, 50,'N', 2,  20,'E') + "<BR>");
  67. %>

on obtiendra le résultat suivant :

Distance entre Montréal et Paris en Km: 5510.16761889
Distance entre Montréal et Paris en Miles: 3423.85470217
Distance entre Montréal et Paris en Miles Nautique: 2975.30044884

Voir également

Langage de programmation - Visual Basic .NET (VB .NET) - Calcul la distance entre deux coordonnées de Longitude et Latitude
Langage de programmation - C# (C Sharp) - Calcul la distance entre deux coordonnées de Longitude et Latitude

PARTAGER CETTE PAGE SUR
Dernière mise à jour : Samedi, le 31 août 2017