gpt4 book ai didi

javascript - 两个地点之间的距离 - Google map

转载 作者:行者123 更新时间:2023-12-03 01:14:59 25 4
gpt4 key购买 nike

我正在尝试使用谷歌地图查找两点之间的位置。这是我正在使用的代码:

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

最佳答案

如果您还没有这样做,请在 <script> 中显式添加几何库。标签 src="http://maps.googleapis.com/maps/api/js?libraries=geometry&sensor=false">

关于javascript - 两个地点之间的距离 - Google map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10211187/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com