简体   繁体   English

Google标记上的缩放设置

[英]Zoom Setting On Google Marker

I wonder whether someone may be able to help me please. 我想知道是否有人可以帮助我。

I'm using this page to allow users to view markers saved in a MySQL database and to geocode/reverse geocode new marker positions. 我正在使用页面来允许用户查看保存在MySQL数据库中的标记,并对新标记位置进行地理编码/反向地理编码。

I'm able to correctly center the map on the marker which is being loaded from the database, but the problem I'm having is that the map zooms in to it's maximum setting, whereas I would like to be able to set this manually. 我能够正确地将地图居中放置在从数据库加载的标记上,但是我遇到的问题是地图放大到了它的最大设置,而我希望能够手动设置。

I've tried adding another zoom control into my script here: 我尝试在此处的脚本中添加另一个缩放控件:

// add marker
var bounds = new google.maps.LatLngBounds(); 
var loc = new google.maps.LatLng(las[i],lgs[i]);
var marker = new google.maps.Marker({
position: loc, 
map: window.map,
zoom: 8,
title: nms[i]
});
bounds.extend(loc);
map.fitBounds(bounds);

Unfortunately this has no affect. 不幸的是,这没有影响。 I appreciate that to some this may be a very minor fix, but I've been looking at this for sometime and I just can't seem to find a solution. 我很欣赏对某些人来说这可能是一个很小的修复,但是我一直在研究这个问题,但似乎找不到解决方案。

I just wondered whether someone may be able to look at this please and let me know where I've gone wrong? 我只是想知道是否有人可以看一下这个,让我知道我哪里出了问题?

POST UPDATE 发布更新

I have worked out a solution using exisitng code and that suggested by @Andrew Leach. 我已经使用exisitng代码制定了一个解决方案,并提供了@Andrew Leach建议的解决方案。 The working solution is: 可行的解决方案是:

// add marker
var bounds = new google.maps.LatLngBounds(); 

var loc = new google.maps.LatLng(las[i],lgs[i]);
var marker = new google.maps.Marker({
position: loc, 
map: window.map,            
title: nms[i]
});
bounds.extend(loc);
map.fitBounds(bounds);
map.setZoom(16);

Remove the references to the bounds . 删除对bounds的引用。

You add a marker to the map, and create a LatLngBounds object which contains only that single point. 您将标记添加到地图,并创建包含单个点的LatLngBounds对象。 You then ask the map to zoom in to fit the bounds into the map's viewport. 然后,您要求地图放大以使边界适合地图的视口。 Fitting a single location into the viewport will always zoom in as far as it can, and even then a single point can never fill the entire viewport. 将单个位置装配到视口中将始终始终尽可能放大,即使那样,单个点也永远无法填满整个视口。

However, adding zoom to the marker options won't work either, because zoom is not a valid option. 但是,将zoom添加到标记选项也将不起作用,因为zoom不是有效的选项。 Documentation 文献资料

Instead, set the map's zoom explicitly, either with map.setZoom(8) or by including the zoom option in the map's options when you set it up. 相反,可以使用map.setZoom(8)显式设置地图的缩放map.setZoom(8) ,或者在设置地图时将zoom选项包含在地图选项中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM