根据针对邮政编码的邻近度查询获取地点

时间:2019-07-17 20:10:30

标签: php google-places-api google-places proximity

我很难弄清楚如何完成特定类型的brew update brew install pyenv pyenv install 3.7.3 pyenv local 3.7.3 make virtualenv 请求。

我有一个Google Places API,我想知道是否有zipcode

我找到了以下示例any hospitals within 20 miles of the zipcode代码,并将请求更改为maps,但是没有执行我想要的操作。

因此,总而言之,我只希望可以将一个api请求转换为hospitals,其中包含一个邮政编码范围20英里内的可用医院的数组,否则为一个空数组。我还可以将存在医院的布尔值或否则为false的布尔值作为输出

PHP

1 个答案:

答案 0 :(得分:0)

Nearby SearchText Search服务将更适合您的用例,因为您希望获得多家医院而不仅仅是一家医院(“查找位置”仅返回一个位置)。

请尝试下面的代码示例,该示例显示距Pyrmont NSW 2009 20英里范围内的医院。请注意,位置必须是LatLng对象,不能是邮政编码,但是使用文本搜索,您可以将其添加到查询中。然后将类型设置为医院。

<script>
    var map;
    var service;

    function initialize() {
        var pyrmont = new google.maps.LatLng(-33.8665433,151.1956316);

        map = new google.maps.Map(document.getElementById('map'), {
            center: pyrmont,
            zoom: 13
        });

        var request = {
            location: pyrmont,
            radius: '32186',
            query: '2009',
            type: 'hospital'
        };

        service = new google.maps.places.PlacesService(map);
        service.textSearch(request, callback);
    }

    function callback(results, status) {
        if (status == google.maps.places.PlacesServiceStatus.OK) {
            for (var i = 0; i < results.length; i++) {
                var place = results[i];
                createMarker(results[i]);
            }
        }
    }

    function createMarker(place) {
        var marker = new google.maps.Marker({
            map: map,
            position: place.geometry.location,
            title: place.name
        });

        google.maps.event.addListener(marker, 'click', function() {
            infowindow.setContent(place.name);
            infowindow.open(map, this);
        });
    }
</script>

希望这会有所帮助!