【问题标题】:Nearby places not showing up?附近的地方不显示?
【发布时间】:2015-04-23 05:10:01
【问题描述】:

我有这段代码,它应该在谷歌地图上创建带有附近地点的标记到已经存在的标记。我的地图和原始市场(不在此代码中)工作正常,但附近的地方似乎不行。

<script type="Javascript">
    function showFood(marker) {

        var request = {
            location: marker.position,
            radius: '1000',
            query: 'food, college, library, gym, bar'
        };
        map: map;
        service = new google.maps.places.PlacesService(map);
        service.textSearch(request, callback2);
    }

    function callback2(results, status) {
        if (status == google.maps.places.PlacesServiceStatus.OK) {
            for (var i = 0, result; result = results[i]; i++) {
                console.log("Results:");
                console.log(result);
                var marker = new google.maps.Marker({
                    map: map,
                    position: result.geometry.location,
                    console.log(position);
                    title: "",
                    visible: true
                });
                google.maps.event.addListener(marker, 'click', function() {
                        showFood(marker);

                    }
                }
            }
        }
    }
</script>

任何帮助将不胜感激。谢谢。

【问题讨论】:

标签: javascript html google-maps-api-3 google-places-api


【解决方案1】:

你的 for 循环看起来很奇怪,应该是这样的

for (i = 0; i < results.length; i++) {
...
}

你什么时候第一次调用 showFood 因为我只能在你的回调函数中看到它。我猜你是在创建初始标记后调用它?如果你不是,那么你发布的代码永远不会被调用。

【讨论】:

    猜你喜欢
    • 2017-08-24
    • 1970-01-01
    • 2016-12-17
    • 2017-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-24
    相关资源
    最近更新 更多