distanceFrom

distanceFrom

書式

distanceFrom(other)

説明

2点間の距離をメートル単位で返します。ただし、最大0.3%の誤差が発生します。

サンプルコード [実行]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps API2 Sample</title>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAasAJryKxWJnBFVJa487d9hTHGAxTVT7IRADYa-JdYz7xQ8IQZBSthgDZdggYpQHsmm6WYtHstQFfLA" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
window.onload = function() {
var map = new GMap2(document.getElementById("map"));
var mapPoint1 = new GLatLng(37,136);
map.setCenter(mapPoint1, 5,G_NORMAL_MAP);
var mapPoint2 = new GLatLng(37.1,136.2);
alert(mapPoint1.distanceFrom(mapPoint2));
}
//]]>
</script>
</head>
<body>
<div id="map" style="width: 500px; height: 400px"></div>
</body>
</html>