22
Tôi đang cố gắng tìm vị trí giữa hai điểm sử dụng bản đồ google. Dưới đây là đoạn code mà tôi đang làm việc với:Khoảng cách giữa hai vị trí - 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));
}
Đây là lỗi tôi nhận được từ giao diện điều khiển:
Uncaught TypeError: Cannot read property 'spherical' of undefined
Cảm ơn! Đây chính xác là những gì tôi đã mất tích. – cclerville
Cũng cần sử dụng URL ở trên; nghĩa là, 'http: //maps.google.com/maps/api/js? sensor = false &? libraries = geometry' sẽ không hoạt động. – Arthur
@Arthur đó là vì bạn đã quên xóa dấu chấm hỏi. '&? library = geometry' phải là' & libraries = geometry' – jimmystormig