谷歌放置API不适用于Meteor

google places api not working for meteor

本文关键字:适用于 Meteor 不适用 API 谷歌      更新时间:2023-09-26
Template.home.onCreated(function() {
    // We can use the `ready` callback to interact with the map API once the map is ready.
    GoogleMaps.ready('Map', function(map) {
        // Add a marker to the map once it's ready
        var marker = new google.maps.Marker({
            position: map.options.center,
            map: map.instance
        });
        var request = {
            location: map.options.center,
            radius:10000,
            types:['restaurant']
        }
        console.log(request)
        var service = new google.maps.places.PlacesService(map);
        service.nearbySearch(request,callback);
        console.log("Calling Service")
        function callback(results,status)
        {
            console.log("Service Called")
            if(status === google.maps.places.PlacesServiceStatus.OK)
            {
                console.log("Status OK")
                for(var i = 0;i < results.length;i++)
                {
                    console.log(results[i])
                    createMarker(results[i]);
                }
            }
        }//end of callback
        function createMarker(place)
        {
            var placeLoc = place.geometry.location;
            var marker = new google.maps.Marker({
                map:map,
                position:place.geometry.location
            });
        }//end of create marker
    })//end of google maps.ready function
});

我有一个简单的应用程序,旨在在地图上的结果上搜索地点和位置标记。地图正确呈现,我已经在普通的 html 和 js 应用程序上尝试了相同的设置。我在流星应用程序中实现它时遇到问题。应用程序在到达var service = new google.maps.places.PlacesService(map);调用后停止,我在控制台Uncaught TypeError: this.j.getElementsByTagName is not a function上收到此错误。我正在使用dburles:google-maps包。

当您需要传递 map.instance new google.maps.places.PlacesService(map.instance) 时,您正在将地图传递给新的google.maps.places.PlacesService(map

请参阅链接以获取参考 https://github.com/dburles/meteor-google-maps#ready