javascript 如何在新的 Google 地图上设置默认缩放级别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19290889/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 15:01:36  来源:igfitidea点击:

How to set the default zoom level on new Google Maps?

javascriptgoogle-mapsembed

提问by netdjw

I readed many question, map help, product forums and so on... but I never find the answer just this "It is not possible". I can't believe it.

我阅读了很多问题、地图帮助、产品论坛等等……但我从来没有找到“这不可能”的答案。我不敢相信。

So how can I set the default zoom level on an embed Google Map?

那么如何在嵌入的 Google 地图上设置默认缩放级别?

Now I have this link for my map: https://mapsengine.google.com/map/edit?mid=zV4QqQ0y5KZs.kFj05lIIpS5s

现在我的地图有了这个链接:https: //mapsengine.google.com/map/edit?mid=zV4QqQ0y5KZs.kFj05lIIpS5s

I was tried thi z=10parameter in the URL, it doesn't work. Is there any other parameter, or maybe something JavaScripttricks to set up the zoomlevel? Or something other HTML parameter like data-zoomor something...?

z=10在 URL中尝试了这个参数,它不起作用。是否有任何其他参数,或者JavaScript设置缩放级别的技巧?或者其他 HTML 参数之类的data-zoom东西……?

回答by Nat

It seems the &z=nnparameter now works.

看来&z=nn参数现在可以工作了。

Try this:

试试这个:

https://mapsengine.google.com/map/viewer?mid=zV4QqQ0y5KZs.kFj05lIIpS5s&z=10

https://mapsengine.google.com/map/viewer?mid=zV4QqQ0y5KZs.kFj05lIIpS5s&z=10

回答by Olav Gausaker

I use this code to initialize my map:

我使用此代码来初始化我的地图:

var map;
function initialize() {
    var mapOptions = {
    zoom: 6,
    center: new google.maps.LatLng(40, -3),
    mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);

That's centered in Spain.

这以西班牙为中心。

回答by mb25035

The new embedded google maps do not have the Z index more, you have to firstset the zoom level you want on the google maps site, and afther thatclick on the setting button and get the iframe code for the zoomed map. You can not change the zoom level in the setting window, that is why you have to zoom the map first directly in the google maps.

新嵌入的谷歌地图没有更多的Z索引,你必须在谷歌地图网站上设置你想要的缩放级别然后点击设置按钮并获取放大地图的iframe代码。您无法在设置窗口中更改缩放级别,这就是为什么您必须首先直接在 google 地图中缩放地图。

Than paste this code in your html page and it should work, at least this worked for me.

比将此代码粘贴到您的 html 页面中,它应该可以工作,至少这对我有用。