2013-10-20

Google Maps API:TIPS

◆距離を求める

3行目。"google.maps.geometry.spherical.computeDistanceBetween"を使う。
distanceの単位は(m)
var positionA = new google.maps.LatLng(latA,lngA);
var positionB = new google.maps.LatLng(latB,lngB);
var distance = google.maps.geometry.spherical.computeDistanceBetween(positionA, positionB);

尚、Google Maps APIをロードする際の引数にgeometryライブラリを追加してやる必要がある。
(URL引数にlibraries=geometryを追加する)
<script src="http://maps.googleapis.com/maps/api/js?libraries=geometry&sensor=false"></script> 

http://choni-waniwani.blogspot.jp/2011/07/google-maps-javascript-api-v32.html


◆sensor= は不要

下記の通り、sensor= は不要になった。

SensorNotRequired Warning 
The sensor parameter is no longer required for the Google Maps JavaScript API. It won't prevent the Google Maps JavaScript API from working correctly, but we recommend that you remove the sensor parameter from the script element.

<script src="http://maps.googleapis.com/maps/api/js?sensor=false"></script> 
のsensor=falseは不要。
<script src="http://maps.googleapis.com/maps/api/js"></script> 
でOK。

◆.sphericalを使う

libraries=geometryが必要。

<script src="http://maps.googleapis.com/maps/api/js?libraries=geometry"></script> 



以上