22
Googleマップを使用して2つの地点の間の場所を探しています。ここで私が働いているコードは次のとおりです。2つの地点間の距離 - Google Maps
function initialize() {
var myOptions = {
center: new google.maps.LatLng(36.8813329,-103.6975488),
zoom: 4,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
var impactCoordinates = [
new google.maps.LatLng(37.772323, -122.214897),
new google.maps.LatLng(34.1633766,-81.6487862),
];
var ImpactPath = new google.maps.Polyline({
path: impactCoordinates,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2
});
ImpactPath.setMap(map);
var loc1 = new google.maps.LatLng(37.772323, -122.214897);
var loc2 = new google.maps.LatLng(34.1633766,-81.6487862);
alert(google.maps.geometry.spherical.computeDistanceBetween(loc1, loc2));
}
これは私がコンソールから取得エラーです:
Uncaught TypeError: Cannot read property 'spherical' of undefined
ありがとう!これはまさに私が欠けていたものです。 – cclerville
上記のURLを使用する必要もあります。つまり、http://maps.google.com/maps/api/js?sensor = false&?libraries = geometry'は機能しません。 – Arthur
@Arthurは疑問符を削除するのを忘れたからです。 '&?libraries = geometry'は'&libraries = geometry'です。 – jimmystormig