Vous avez trouvé ce tutoriel intéressant ? Recommandez le en cliquant sur le bouton +1    

Bibliothèque Géométrie - Exemple computeArea MVCArray

Tutoriel publié le
Tutoriel en Français

Calculer la surface d'un Polygone à l'aide de computeArea et MVCArray

Ce tutoriel vous explique comment calculer la surface délimitée par six points via MVCArray et computeArea.

  • 1 - Tours - FR - Latitude : 47.390912, Longitude : 0.670166
  • 2 - Dakar - SN - Latitude 14.762931, Longitude : -17.339172
  • 3 - Djibouti - DJ - Latitude 11.588847, Longitude : 43.146572
  • 4 - Moscou - RU - Latitude 55.753395, Longitude : 37.626114
  • 5 - Reykjavík - IS - Latitude 64.133529, Longitude : -21.898499
  • 6 - San Francisco - US - Latitude 37.771529, Longitude : -122.427177

Exemple de code

<!DOCTYPE html>
<html lang="fr">
<head>
	<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
	<meta charset="UTF-8" />
	<title>Titre de votre page</title>
	<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=geometry"></script>
	<script type="text/javascript">
	function initialize(){
		var MvcArrayPerso = new google.maps.MVCArray(); 
			MvcArrayPerso.push(new google.maps.LatLng(47.390912,0.670166)); 
			MvcArrayPerso.push(new google.maps.LatLng(14.762931,-17.339172)); 
			MvcArrayPerso.push(new google.maps.LatLng(11.588847,43.146572)); 
			MvcArrayPerso.push(new google.maps.LatLng(55.753395,37.626114)); 
			MvcArrayPerso.push(new google.maps.LatLng(64.133529,-21.898499)); 
			MvcArrayPerso.push(new google.maps.LatLng(37.771529,-122.427177));
		var surface = google.maps.geometry.spherical.computeArea(MvcArrayPerso);
		document.getElementById('info').innerHTML = "Surface délimitée par ces 6 points : "+surface+" mètres";
	}
	</script>
</head>
<body style="margin:0px; padding:0px;" onload="initialize()">
	<div id="info"></div>
	<noscript>
	<p>Attention : </p>
	<p>Afin de pouvoir utiliser Google Maps, JavaScript doit être activé.</p>
	<p>Or, il semble que JavaScript est désactivé ou qu'il ne soit pas supporté par votre navigateur.</p>
	<p>Pour afficher Google Maps, activez JavaScript en modifiant les options de votre navigateur, puis essayez à nouveau.</p>
	</noscript>
</body>
</html>