Я пытаюсь установить маркер по определенному адресу и показать близлежащие рестораны в радиусе 500 метров. Маркер и рестораны показаны, но радиус игнорируется. Я уже получил 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 (), но в этом случае мне потребуется соседний поиск ().
Когда я использую https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=my_lat,my_lng&radius=500&types=restaurant&key="my_key", я получаю необходимые результаты (в моем случае 8).
Но с поиском текста вместо поиска поблизости я получаю 20 элементов, и некоторые из них находятся за пределами моего радиуса 500 метров.