【发布时间】:2020-08-07 16:55:25
【问题描述】:
如何显示在我的中心半径内的标记?我需要根据半径显示地点,因为这将是我根据地点的公里半径创建查找此类地点的功能的基础。
如您所见,我有很多标记。通过调用 axios 请求来自我的数据库。
这是我的代码 sn-p
data() {
return {
clinics: [],
points: '',
property: {
lat: 1.28237,
lng: 103.783098
},
diameter: 5000
}
},
methods: {
initMap() {
//center marker from circle
const map = new google.maps.Map(document.getElementById('map'), {
zoom: 13,
center: this.property
})
const circle = new google.maps.Circle({
map: map,
trokeColor: '#FF0000',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#FF0000',
fillOpacity: 0.35,
radius: this.diameter,
center: this.property
});
const marker = new google.maps.Marker({
position: this.property,
map: map
});
//other Markers
for (var i = 0; i < this.clinics.data.length; i++) {
var coords = this.clinics.data[i].coord;
var details = this.clinics.data[i].clinic;
var latLng = new google.maps.LatLng(coords['lat'], coords['lng']);
var markers = new google.maps.Marker({
position: latLng,
map: map,
});
const contentString = '<div id="content"><p>' + details + '</p></div>';
//for Info window function
this.infoWindowShow(markers, contentString);
}
}
【问题讨论】:
-
如果您只对圈内的标记感兴趣,为什么要加载所有标记? + 我已经向您指出了有关如何根据中心点和半径查询数据库以查找标记的完整答案。这不适合你吗?
-
是的,它对我不起作用,先生@MrUpsidown
-
什么不起作用? 它不起作用 不是问题描述+您上面的代码没有显示任何沿着这条路走的尝试。然而,这将是一个比您接受的解决方案更好的解决方案。
标签: javascript google-maps vue.js google-maps-api-3