22
Google지도를 사용하여 두 지점 사이의 위치를 찾으려고합니다. 두 위치 간 거리 - Google지도
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