首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >google.maps.LatLng对google.maps.LatLngLiteral

google.maps.LatLng对google.maps.LatLngLiteral
EN

Stack Overflow用户
提问于 2019-02-06 02:52:21
回答 1查看 2.1K关注 0票数 0

我正在将谷歌地图添加到我正在开发的应用程序中,并且成功地解决了一个可能对我的应用程序没有任何影响的问题。

无论如何,我很好奇为什么Google允许您使用new google.maps.LatLng(x, y){lat: x, lng: y}

我用过这两种格式,看上去完全没有区别,但我觉得我一定是错过了什么.我不敢相信google.map.LatLng的存在没有具体的目的。

这是:

代码语言:javascript
复制
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
  }

或者这个:

代码语言:javascript
复制
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
  }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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作为输入。
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54545979

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档