搜索结果的Google Polymer <google-map-search>位置和半径将被忽略

时间:2018-06-26 13:59:08

标签: javascript polymer

我正在尝试将标记设置为特定地址,并显示半径500m以内的附近餐馆。显示了标记和餐厅,但忽略了半径。我一直得到20个餐厅结果。我也在考虑按距离排序并减少元素数量,但无法使其正常工作。

<div slot="content"
            title="">
            <div class="title">[[title]]</div>

            <google-map-search id="gps"
                               map="[[map]]"
                               query="[[mapQuery]]"
                               results="{{results}}">
            </google-map-search>

            <google-map-search id="restaurantID"
                               map="[[map]]"
                               query="[[mapQuery]]"
                               location="[[location]]"
                               radius="[[radius]]"
                               types="[[types]]"
                               results="{{restaurantResults}}">

            </google-map-search>

            <div class="map">
                <google-map map="{{map}}"
                            id="map"
                            fit-to-markers
                            longitude="[[longitude]]"
                            latitude="[[latitude]]"
                            api-key="[[googleMapApiKey]]"
                            disable-map-type-control
                            disable-street-view-control
                            singleInfoWindow
                            styles="[[mapStyles]]">

                    <template is="dom-repeat"
                              items="{{results}}"
                              as="marker">
                        <google-map-marker latitude="{{marker.latitude}}"
                                           longitude="{{marker.longitude}}"
                                           label="A">   
                            <h2>{{marker.name}}</h2>
                            <span>{{marker.formatted_address}}</span>
                        </google-map-marker>
                    </template>

                    <template is="dom-repeat"
                              items="{{restaurantResults}}"
                              as="marker">
                        <google-map-marker latitude="{{marker.latitude}}"
                                           longitude="{{marker.longitude}}"
                                           label="B"> 
                            <h2>{{marker.name}}</h2>
                            <span>{{marker.formatted_address}}</span>
                        </google-map-marker>
                    </template>

                </google-map>
            </div>
        </div>

我的财产是

static get properties() {
            return {
                title: {
                    type: String
                },
                fields: {
                    type: Array,
                    value: ["str", "plz"]
                },
                googleMapApiKey: {
                    type: String,
                    observer: '_googleMapAPIkeyChanged'
                },
                mapQuery: {
                    type: String
                },
                location: {
                    type: Object,
                    //readOnly: true
                },
                radius: {
                    type: Number,
                    value: "500"
                },
                types: {
                    type: String,
                    value: "restaurant"
                },
            };
        }

后来我设置了this.location = {lat:my_lat,lng:my_lng}。 但是位置和半径将被忽略。结果仅取决于给定的mapQuery。 我认为其原因是的search()函数是textSearch(),但在这种情况下,我将需要附近的search()。

当我使用https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=my_lat,my_lng&radius=500&types=restaurant&key=“ my_key”时,会得到所需的结果(以我的情况为8)。
但是使用textsearch而不是附近的搜索,我得到了20个元素,其中一些在我的500m半径之外。

1 个答案:

答案 0 :(得分:0)

我自己解决了。我将标记项重命名为restaurantResultsView。这样,我可以过滤原始的restaurantResults。