gpt4 book ai didi

javascript - google.maps.geometry.spherical 错误

转载 作者:行者123 更新时间:2023-12-03 03:27:29 27 4
gpt4 key购买 nike

我在使用谷歌地图上的几何图形时遇到一些问题。我收到以下错误:“无法获取未定义或空引用的属性‘球形’。”

这是来自 w3c 的一些代码,加上我的一些补充。

var x=new google.maps.LatLng(52.395715,4.888916);
var stavanger=new google.maps.LatLng(58.983991,5.734863);
var amsterdam=new google.maps.LatLng(52.395715,4.888916);
var london=new google.maps.LatLng(51.508742,-0.120850);
function initialize()
{
var mapProp = {
center:x,
zoom:4,
mapTypeId:google.maps.MapTypeId.ROADMAP
};

var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
var myTrip=[stavanger,amsterdam,london];
var flightPath=new google.maps.Polyline({
path:myTrip,
strokeColor:"#0000FF",
strokeOpacity:0.8,
strokeWeight:2
});
flightPath.setMap(map);

try{
var markerpos = google.maps.geometry.spherical.interpolate(flightPath.getAt(0), flightPath.getAt(1), .5);
// also tried //
//var Spherical = google.maps.geometry.spherical;
//var markerpos = Spherical.interpolate(flightPath.getAt(0), flightPath.getAt(1), .5);
//var markerpos = google.maps.geometry.spherical.interpolate(amsterdam, london, .5);
}
catch(ex){alert(ex);}

var marker = new google.maps.Marker({position: markerpos,
map: map, clickable: false
});
}

上面的代码有什么问题吗?

最佳答案

您正在加载 correct library使用 libraries= 参数?

<script src="https://maps.googleapis.com/maps/api/js?v=3&sensor=false&libraries=geometry"></script>

关于javascript - google.maps.geometry.spherical 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15226053/

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