Javascript 谷歌地图应该通过点击一个按钮,将至少3个最近的标记放在你当前的位置点上
我有一个按钮,应该重定向到你们在地图上的当前位置,但重定向到位置后,地图应该自动缩放,你们应该能够看到至少3个最近的标记 这是我代码的一部分。它唯一能做的就是绑定到所有标记,但不显示我的位置Javascript 谷歌地图应该通过点击一个按钮,将至少3个最近的标记放在你当前的位置点上,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我有一个按钮,应该重定向到你们在地图上的当前位置,但重定向到位置后,地图应该自动缩放,你们应该能够看到至少3个最近的标记 这是我代码的一部分。它唯一能做的就是绑定到所有标记,但不显示我的位置 $('a.geolocation').click(function() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(position) { var bounds =
$('a.geolocation').click(function() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var bounds = new google.maps.LatLngBounds();
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
for (var i=0; i<storeLocator.markers.length; i++) {
if(storeLocator.markers[i].getVisible()) {
bounds.extend( storeLocator.markers[i].getPosition() );
}
}
map.setCenter(pos);
map.fitBounds(bounds);
});
}
});
$('a.geolocation')。单击(函数(){
if(导航器.地理位置){
navigator.geolocation.getCurrentPosition(函数(位置){
var bounds=new google.maps.LatLngBounds();
var pos={
纬度:位置坐标纬度,
lng:position.coords.longitude
};
对于(var i=0;i发生的事情是这样的。您将地图的中心设置为用户的位置。但是,然后您使地图适合您的商店边界,这将调整地图的中心,而不一定使用户的位置可见
你需要做的就是确保位置也在边界内
navigator.geolocation.getCurrentPosition(function(position) {
var bounds = new google.maps.LatLngBounds();
var pos = new google.maps.LatLng(
position.coords.latitude,
position.coords.longitude
);
bounds.extend(pos);
for (var i=0; i<storeLocator.markers.length; i++) {
if(storeLocator.markers[i].getVisible()) {
bounds.extend( storeLocator.markers[i].getPosition() );
}
}
map.setCenter(pos);
map.fitBounds(bounds);
});
navigator.geolocation.getCurrentPosition(函数(位置){
var bounds=new google.maps.LatLngBounds();
var pos=新的google.maps.LatLng(
位置坐标纬度,
位置坐标经度
);
边界扩展(pos);
对于(var i=0;i