ymaps.ready(init);
function init() {
var myMap = new ymaps.Map("map", {
center: \[55.73, 37.75\],
zoom: 12
}, {
searchControlProvider: 'yandex#search'
}),
cafe, metro;
function findClosestObjects () {
cafe.getClosestTo(metro.get(0)).balloon.open();
// Opening the balloon of the cafe that is closest to the click.
myMap.events.add('click', function (event) {
cafe.getClosestTo(event.get('coords')).balloon.open();
});
}
cafe = ymaps.geoQuery({
type: 'FeatureCollection',
features: [{
type: 'Feature',
properties: {
balloonContent: 'Darth Vader coffee shop - we have cookies!'
},
geometry: {
type: 'Point',
coordinates: [55.724166, 37.545849]
}
}, {
type: 'Feature',
properties: {
balloonContent: 'Gollum cafe - lovely cakes.'
},
geometry: {
type: 'Point',
coordinates: [55.717495, 37.567886]
}
}, {
type: 'Feature',
properties: {
balloonContent: 'Brick cafe: strong coffee for strong guys.'
},
geometry: {
type: 'Point',
coordinates: [55.7210180,37.631057]
}
}
]
}).addToMap(myMap);
metro = ymaps.geoQuery(ymaps.geocode([55.744828, 37.603423], {kind: 'metro'}))
.then(findClosestObjects);
}
I have reviewed Yandex's api documentation for javascript. I need a structure or alternative similar to the nearbySearch method for Places Api in Google Maps.
I searched for a method similar to the nearbySearch method used for Google maps and at the end of the day I found the above example with constant variables.