【问题标题】:Google Maps Error: not a LatLng or LatLngLiteral: not an Object - seems to be 'bounds' relatedGoogle Maps Error: not a LatLng or LatLngLiteral: not an Object - 似乎与“边界”相关
【发布时间】:2020-03-03 04:13:33
【问题描述】:

我从谷歌电子表格导入地址并将它们放在谷歌地图上。位置(纬度和经度)存储在变量中。我遍历所有条目并创建标记。 谷歌电子表格和网站之间的连接有效,但它只显示第一个条目。所以这似乎是循环的问题。

首先我认为_location.latitude/_location.longitude 中的值有问题,我尝试在那里设置 .value,但这不是问题。

循环在 _setLocations 函数中,从我的搜索来看,var _bounds_bounds.extend 似乎有一些问题

_createGoogleMap: function(_mapID){

          var _this = this;

          var _locations = [];

          var _sheetUrl = 'https://sheets.googleapis.com/v4/spreadsheets/xxxxxxxxxxxxxxxxxxx/values/Sheet1!A2:U?key=xxxxxxxxxxxxxxxxxxxxxx';

          var _map = new google.maps.Map(document.getElementById(_mapID), this._mapProp);

          $.getJSON(_sheetUrl, function(data) {
            $(data.values).each(function() {
              var _location = {};
                _location.latitude = parseFloat(this[8]);
                _location.longitude = parseFloat(this[9]);
                _locations.push(_location);
            });

            _this._setLocations(_map, _locations);

          });
        },


_setLocations: function(_map, _locations) {

          var _this = this;

          var _bounds = new google.maps.LatLngBounds();

          var _infowindow = new google.maps.InfoWindow({
            content: "Content String"
          });
          for (var i = 0; i < _locations.length; i++) {
            var _new_marker = _this._createMarker(_map, _locations[i], _infowindow);

            _bounds.extend(_new_marker._position);
          }
          _map.fitBounds(_bounds);

        },

当我 'console.log(_locations);'在循环之前, 我得到了所有的地址,但是在循环之后我什么也没得到 没有了。

任何帮助表示赞赏。

【问题讨论】:

  • 谷歌地图LatLngLiteral 具有属性.lat.lng(不是.latitude.longitude)。

标签: javascript json google-maps google-maps-api-3


【解决方案1】:

尝试使用适当的 LatLng 对象

   my_location  = new google.maps.LatLng(_locations[i].latitude, _locations[i].longitude) ;
   var _new_marker = _this._createMarker(_map, _my_location, _infowindow);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-30
    • 2014-01-02
    • 1970-01-01
    • 2019-08-29
    • 2022-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多