繁体   English   中英

谷歌放置 api 不适用于流星

[英]google places api not working for meteor

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);应用程序就会停止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)时,您将地图传递给new google.maps.places.PlacesService(map )

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM