Meteor JS mdg:geolocation + dburles / meteor-google-maps,Google Places库错误

时间:2016-07-04 05:22:45

标签: google-maps meteor google-places

我正在使用mdg:geolocation + dburles / meteor-google-maps加载Google地图并显示本地搜索结果。地图工作正常,地理定位工作正常,但Google商家信息库除外。

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

此问题在大约3个月前被其他用户提出过。但它似乎死了。以下是控制maps / geolocation

的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');

        });
    });
});

1 个答案:

答案 0 :(得分:0)

我正在将地图传递给新的google.maps.places.PlacesService(地图),而我需要传递map.instance new google.maps.places.PlacesService(地图。实例)