由于以下原因,地理编码无法成功:OVER_QUERY_LIMIT

时间:2017-08-18 23:01:29

标签: javascript arrays google-maps location marker

我正在尝试在谷歌地图上生成大量标记的位置,但我意识到这个错误Geocode was not successful for the following reason: OVER_QUERY_LIMIT我在谷歌周围发现并且认为在一个时间范围内查询是有限制的。

我已经阅读了一些关于如何解决它的人的代码,但我不知道如何将它实现到我自己的代码中。

有人可以给我一个手或想法吗?

P.S。我已经阅读了该帖子,这是我可以找到的关闭帖子但是有一些变量,例如delay++address--以及next()我不知道它们来自哪里。我正在阅读发布的脚本和答案脚本,但仍然以某种方式混淆

这是我目前的代码。

    function initMap() {
        var map = new google.maps.Map(document.getElementById('map'), {
            zoom  : 2,
            center: {lat: -34.397, lng: 150.644}
        });
        var geocoder = new google.maps.Geocoder();

        console.log(userAddress);

        function generateMap(userAddress){
            if (userAddress.length > 0){
                for (var i = 0; i < userAddress.length; i++) {
                    geocoder.geocode({'address': userAddress[i]}, (results, status) => {
                        if (status === 'OK') {
                            map.setCenter(results[0].geometry.location);
                            var marker = new google.maps.Marker({
                                map     : map,
                                position: results[0].geometry.location
                            });
                        } else {
                            console.log('Geocode was not successful for the following reason: ' + status);
                        }
                    });
                }
            }
        }

        generateMap(userAddress);

0 个答案:

没有答案