对Google地图标记进行聚类时,对象没有方法'getPosition'(api v3) [英] Object has no method 'getPosition' when clustering Google map markers (api v3)

查看:120
本文介绍了对Google地图标记进行聚类时,对象没有方法'getPosition'(api v3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Google Maps Utility Library v3

当我运行它时,Chrome Developer上出现错误工具控制台:

When I run this though, I get an error on the Chrome Developer Tools console:

Uncaught TypeError: Object #<Object> has no method 'getPosition'

这与实用程序库脚本中的第649行有关: http:// google-maps-utility-library- v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js 。下面的函数是:

This relates to line 649 in the utility library script here: http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js. Which is the following function:

/**
 * Determins if a marker is contained in a bounds.
 *
 * @param {google.maps.Marker} marker The marker to check.
 * @param {google.maps.LatLngBounds} bounds The bounds to check against.
 * @return {boolean} True if the marker is in the bounds.
 * @private
 */
MarkerClusterer.prototype.isMarkerInBounds_ = function(marker, bounds) {
  return bounds.contains(marker.getPosition());
};

我使用的代码是相当标准的Google Maps东西,其主要功能是:

The code I'm using is reasonably standard Google maps stuff, the main function for which is:

function initialize(items,loop,zoom) {
  geocoder = new google.maps.Geocoder();
  if (items.length > 0) {
    var latlng = new google.maps.LatLng(items[0].Lat, items[0].Lng);
    var myOptions = {
      zoom: zoom,
      center: latlng,
      //mapTypeControl: false,
      streetViewControl: false,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    map = new google.maps.Map(document.getElementById("map"), myOptions);
    map.setOptions({styles: stylez});

    for (var i = 0; i < items.length; i++) {
      var marker = new google.maps.Marker({
        position: new google.maps.LatLng(items[i].Lat, items[i].Lng),
        title: items[i].Title,
        icon: _iconCenter,
        shadow: shadow,
        infocontent: items[i].Description
      });
      marker.setMap(map);
      markersArray.push(marker);
    }
    var markerCluster = new MarkerClusterer(map, items);
    google.maps.event.addListener(map, "tilesloaded", function () {
      if(loop == true){
        SetLoop();
      }
    });
  }
}

我追溯了错误函数,我明白,它应该接收地图边缘的坐标,以便能够确定边界,这应该只是标准的行为,但显然有些东西是不正确的。

I've traced the erroring function back as far as I understand and it should be receiving coordinates for the edges of the map to be able to determine the bounds, which should be just standard behaviour, but clearly something's not right.

我想知道是否有人可以解释这一点?

I wondered if anyone could shed any light on this?

感谢任何指点人......

Thanks for any pointers folks...

推荐答案

问题原来是我在Google Maps脚本之前宣布了markerclusterer脚本。调用地图脚本首先解决了它......现在显而易见!

The issue turned out to be the fact that I was declaring the markerclusterer script before the google maps script. Calling the maps script first solved it... obvious now!

这篇关于对Google地图标记进行聚类时,对象没有方法'getPosition'(api v3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆