【问题标题】:Meteor JS mdg:geolocation + dburles/meteor-google-maps, Google Places library errorMeteor JS mdg:geolocation + dburles/meteor-google-maps, Google Places 库错误
【发布时间】:2016-07-07 10:58:39
【问题描述】:

我正在使用 mdg:geolocation + dburles/meteor-google-maps 加载 Google 地图并显示本地结果。地图工作正常,地理位置工作正常,除了谷歌地方图书馆。

我收到以下错误“未捕获的 TypeError:this.j.getElementsByTagName 不是函数”。即使没有两个包集成,我也可以让 Google Places 在 Meteor 之外工作。

大约 3 个月前,另一位用户曾问过此问题。但它看起来像线程死了。这是我在控制地图/地理位置的 js 文件中的以下代码

Meteor.startup(function() {  
  GoogleMaps.load({
    v : '3',
    key: 'mYKeyinHereBLAHABLAHBLAH',
    libraries: 'places'
  });
});

Template.map.helpers({ 
    //get current lat & lng and create map 
    geolocationError: function() {
        let error = Geolocation.error();
        return error && error.message;
    },
    mapOptions: function() {
        let latLng = Geolocation.latLng();
        // Initialize the map once we have the latLng.
        if (GoogleMaps.loaded() && latLng) {
            return {
                center: new google.maps.LatLng(latLng.lat, latLng.lng),
                zoom: 15
            };
        }
    }
});

Template.map.onRendered(function() { 
    let self = this; 

    GoogleMaps.ready('map', function(map) {
        let latLng = Geolocation.latLng();

        let marker;
        self.autorun(function() {
            //set user location
            let marker = new google.maps.Marker({
                position: new google.maps.LatLng(latLng.lat, latLng.lng),
                map: map.instance
            });
            marker.setPosition(latLng);
            map.instance.setCenter(marker.getPosition());
            map.instance.setZoom(15);

            //google places
            let Places = function(locationType){
                this.locationType = locationType;

                let place = new google.maps.places.PlacesService(map);
                place.nearbySearch({
                    location: latLng,
                    radius: 16100, //10 mile radius
                    keyword: [locationType]
                }, getPlace);

                function getPlace(results, status) {
                    if (status === google.maps.places.PlacesServiceStatus.OK) {
                        for (let i = 0; i < results.length; i++) {
                            console.log(results[i]);
                            createPlaceMarkers(results[i]);
                        }
                    }
                }

                function createPlaceMarkers(place) {
                    let placeLocation   = place.geometry.location,
                        placeMaker      = new google.maps.Marker({
                            map: map,
                            position: place.geometry.location,
                            draggable:false,
                            zIndex: 9997
                        });
                }
            }

            let bars    = new Places('Bar'),
                club    = new Places('Night Club');

        });
    });
});

【问题讨论】:

    标签: google-maps meteor google-places


    【解决方案1】:

    我将地图传递给 new google.maps.places.PlacesService(map) 而我需要传递 map.instance new google.maps.places.PlacesService(map.实例)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-05
      • 2012-05-10
      • 1970-01-01
      • 1970-01-01
      • 2017-02-08
      • 1970-01-01
      • 2020-05-11
      • 2014-02-18
      相关资源
      最近更新 更多