- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
到目前为止我采用的方法是:
function addMarker( query ) {
var geocoder = new google.maps.Geocoder();
var afterGeocode = $.Deferred();
// Geocode 'query' which is the address of a location.
geocoder.geocode(
{ address: query },
function( results, status ){
if( status === 'OK' ){
afterGeocode.resolve( results ); // Activate deferred.
}
}
);
afterGeocode.then( function( results ){
var mOptions = {
position: results[0].geometry.location,
map: map
}
// Create and drop in marker.
var marker = new google.maps.Marker( mOptions );
marker.setAnimation( google.maps.Animation.DROP );
var current_bounds = map.getBounds(); // Get current bounds of map
// use the extend() function of the latlngbounds object
// to incorporate the location of the marker
var new_bounds = current_bounds.extend( results[0].geometry.location );
map.fitBounds( new_bounds ); // fit the map to those bounds
});
}
我遇到的问题是 map 莫名其妙地缩小了一些,无论新标记是否适合当前视口(viewport)。
我做错了什么?
附录
我添加了日志和一个额外的变量来捕获 map 边界之后进行了转换(new_new_bounds)
current_bounds = // Map bounds before anything is done.
{-112.39575760000002, 33.60691883366427},
{-112.39295444655761, 33.639099}
new_bounds = // From after the extend
{-112.39295444655761, 33.60691883366427},
{-112.39575760000002, 33.639099}
new_new_bounds = // From after the fitbounds
{-112.33942438265382, 33.588697452015374},
{-112.44928766390382, 33.657309727063996}
最佳答案
好吧,经过多次争论,问题出在 map 的边界与 fitBounds()
之后的 map 边界不同。会发生什么(我推测)是 Google 接受您在 fitBounds()
方法中给它的边界,然后填充它们。每次将当前边界发送到 fitBounds()
时,您不会拟合边界 (x,y),而是拟合边界 (x+m,y+m),其中m = 任意边距。
也就是说,最好的方法是:
var current_bounds = map.getBounds();
var marker_pos = marker.getPosition();
if( !current_bounds.contains( marker_pos ) ){
var new_bounds = current_bounds.extend( marker_pos );
map.fitBounds( new_bounds );
}
因此,只有当放置的标记落在当前 map 边界之外时, map 才会适合边界。希望这对遇到此问题的其他人有所帮助。
关于javascript - 将 Google map 视口(viewport)设置为自动适合不同位置的 (n) 个标记位置的 Pane ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5997633/
我想检测鼠标何时离开顶部的视口(viewport)(可以说是向北)。我在网上搜了下How can I detect when the mouse leaves the window? .是一个好的开始
我有一个 HTML 元素,宽 1000 像素,高 850 像素(它实际上是一个 iFrame,在 canvas 标签上包含一个 HTML5 游戏,但我希望这不会有影响)。 我希望元素在平板电脑上呈现,
我正在创建一个 2D 引擎,我想实现对接,所以我需要创建一个视口(viewport)并将屏幕渲染为纹理。 为了渲染视口(viewport),我将帧缓冲区保存到一个 FrameBufferObject
大多数移动页面都提供元视口(viewport)尺寸,例如 出于 iphone 向后兼容的原因,这将在宽度上模拟 320px... 但是当我通过 javascript 检查时 window.screen
我有一个客户提供的宽度为 1440 像素的网站。客户要求我使用以下方法将视口(viewport)设置为 1440 像素对于桌面浏览器,小于 1440 像素的屏幕不显示滚动条。 它确实适用于移动设备、i
我刚刚读了一篇 nice article on viewport这给我留下了几个关于移动设备上的视觉视口(viewport)与布局视口(viewport)的问题。 the width and the
layout viewport和visual viewport的解释可以找到here . 我已阅读 here和 here那个应该使用 如果想针对移动设备优化网页。 我想了解这对横向模式下的 ipho
我想用javascript获取视口(viewport)宽度。但不是常见的虚拟视口(viewport)。我需要逻辑硬件视口(viewport),在我的情况下,它不是设置视口(viewport)元标记的选
我有一个 menu 元素,如果 menu 元素变得在视口(viewport)之外,我想固定到浏览器视口(viewport)的顶部由于滚动。从概念上讲,我的网页看起来类似于下面的示例 HTML,其中菜单
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 4 年前。 Improve this qu
我只包含了“main”的 HTML 代码,因为这是我希望能够通过媒体查询控制的部分。我希望内容只能在小于 480 像素的视口(viewport)上查看,但浏览器似乎隐藏了所有视口(viewport)尺
我不知道如何描述这个,所以最好的办法是链接一个例子:http://www.pascalvangemert.nl/#/profile 无论这个人对侧边栏菜单做了什么都很棒,我很想复制它。我试过检查,但我
我遇到了一页末尾有空白的问题。据我所知,没有元素占据空间。仅当视口(viewport)设置为特定宽度时才会出现该空间。例如,它出现在宽度 940 和 400 左右,但不是 550 或非常宽。 起初我以
iPhone/iPad 等移动设备的视觉视口(viewport)和布局视口(viewport)有什么区别? 网上查了很多资料,还是不清楚。 最佳答案 视觉视口(viewport)是当前显示在屏幕上的页
我正在使用这个元标记来设置移动浏览器上的视口(viewport)大小: 和这个 css 以确保较大的图像不会导致在较小的视口(viewport)上滚动: img { max-width: 95%;
这是针对平板电脑浏览器的,它使用相对于视口(viewport)宽度/高度的尺寸。为简单起见,假设横向。 我在一个全屏容器中有两个 div,就像提供的图像一样。他们有 position:absolute
我在 opengl 中创建了一个迷宫,并且正在尝试创建一个小 map 。为此,我想到在视口(viewport)内创建一个视口(viewport)。我有三种方法,一种用于创建墙壁,另一种用于创建地板,另
所以我有 2 个屏幕:一个级别选择屏幕,使用分辨率为 720 x 405 的 FitViewport,然后是一个游戏屏幕,使用分辨率为 480 x 270 的 FillViewport,按每米像素数
无论视口(viewport)的宽度如何,我都有一个图像幻灯片,我试图将其置于视口(viewport)的中心。如果视口(viewport)比图像宽,使用 margin: auto; 很容易实现,但是,当
我有一个元素,该元素具有从屏幕边缘底部弹出并循环向下弹出(虽然不是完全向下)的动画。下面的代码对此非常有用。但是,有一个问题。当浏览器全屏显示时,百分比占旧视口(viewport)大小而不是新视口(v
我是一名优秀的程序员,十分优秀!