我正在将谷歌地图添加到我正在开发的应用程序中,并且成功地解决了一个可能对我的应用程序没有任何影响的问题。
无论如何,我很好奇为什么Google允许您使用new google.maps.LatLng(x, y)或{lat: x, lng: y}
我用过这两种格式,看上去完全没有区别,但我觉得我一定是错过了什么.我不敢相信google.map.LatLng的存在没有具体的目的。
这是:
function initMap() {
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer();
var chicago = new google.maps.LatLng(41.850033, -87.6500523);
var mapOptions = {
zoom:7,
center: chicago
}或者这个:
function initMap() {
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer();
var chicago = {lat: 41.850033, lng: -87.6500523);
var mapOptions = {
zoom:7,
center: chicago
}发布于 2019-02-06 03:30:54
google.maps.LatLng是最初的类( API的最早版本没有google.maps.LatLngLiteral),大多数(但不是全部)接受google.maps.LatLng的函数也接受google.maps.LatLngLiteral ({lat: x, lng: y})。
google.maps.LatLngLiteral的优点是它不需要加载API来使用它,它可以在加载API之前使用和初始化。google.maps.LatLng的优点是某些函数(主要是 library中的函数)只接受google.maps.LatLng作为输入。https://stackoverflow.com/questions/54545979
复制相似问题