Javascript新手,如何将对象传递给构造函数?
我正在用Python编写一个程序,但有一小部分需要使用仅在Javascript中可用的GoogleAPI函数,所以我正在尝试将这些内容组合起来Javascript新手,如何将对象传递给构造函数?,javascript,google-maps-api-3,Javascript,Google Maps Api 3,我正在用Python编写一个程序,但有一小部分需要使用仅在Javascript中可用的GoogleAPI函数,所以我正在尝试将这些内容组合起来 var swl = new google.maps.LatLng({lat: 55.857128, lng: -4.272051}); var nel = new google.maps.LatLng({lat: 55.867147, lng: -4.245272}); var boundsRectangle = new google.maps.LatL
var swl = new google.maps.LatLng({lat: 55.857128, lng: -4.272051});
var nel = new google.maps.LatLng({lat: 55.867147, lng: -4.245272});
var boundsRectangle = new google.maps.LatLngBounds({sw:swl, ne:nel});
window.alert(boundsRectangle.getNorthEast());
第3行似乎有一些问题。例如,我尝试过打印swl.lat(),这样可以使swl和nel看起来很好,但window.alert从未创建,因此它似乎在那里被破坏
对于第三行,Google说LatLngBounds类有一个构造函数:
LatLngBounds(sw?:LatLng, ne?:LatLng)
其中,LatLng是对象。所以我假设我只是格式化了这个错误——“LatLngBounds({sw:swl,ne:nel})”
新的google.maps.LatLngBounds
不接受对象作为参数,它需要两个google.maps.LatLng
对象。读@Pointy。LatLng也不接受对象,它接受两个浮点值
var boundsRectangle = new google.maps.LatLngBounds(
new google.maps.LatLng(55.857128, -4.272051),
new google.maps.LatLng(55.867147, -4.245272)
);
也许它应该是
.LatLngBounds(swl,nel)