有没有办法根据图像的可用性来设置 Google 静态地图的缩放级别?
我在工作环境中为客户使用静态地图。我喜欢 17 的缩放级别(0 表示整个地球,21 表示最接近的缩放),但根据图像位置的来源,Google 可能无法提供缩放级别 17 的图像。是一种方法吗? ,告诉 Maps API,动态选择可能的最高缩放,例如 17?我还没有找到一种方法来做到这一点,但我非常感谢任何建议。
I use Static maps in my work inviroment for customers. I like the zoom level of 17, (0 for the entire earth, 21 for the closest zoom possible) but depending on where the image location is from, Google may not have the imagery available at the zoom level of 17. Is the a way, to tell the Maps API, to dynamically select the highest zoom possible, up to say 17? I have not seen a way to do this, but i sure appreciate any suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,静态地图必须在网址的查询字符串中设置缩放,例如
&zoom=17
或&z=17
如果您如果使用非静态地图,您可以轻松找到和/或设置最大缩放:
鉴于您使用的是静态,我认为您有两个选择:
编辑
这是实现缩放 js 的一种方法。 (我很感兴趣,并将其一起破解。我确信有更好/更优雅的方法)
HTML
确保缩放级别位于查询字符串的末尾。
JS
http://jsfiddle.net/jasongennaro/FFTKG/2/
As far as I know, static maps must have the zoom set in the query string of the url, something like
&zoom=17
or&z=17
If you were using a non-static map, you could easily find and/or set the max zoom:
Given that you are using static though, I think you have two options:
EDIT
Here's one way to implement the js for the zoom. (I was interested and hacked this together. I am sure there is a better/more elegant way)
HTML
Make sure the zoom level is at the end of the query strings.
JS
http://jsfiddle.net/jasongennaro/FFTKG/2/
首先,我要感谢 Jason Gennaro 提出了一个令人惊叹的 JS 替代方案!不幸的是,这个想法假设您在每个地图上设置了“缩放”级别。如果像我的情况一样,我让谷歌(原文如此)本身调整地图大小,我就会对 Jason 的代码进行修改/添加。如果您想使用他的想法,但希望地图在 2 个位置周围正确调整大小,使用每个位置的纬度/经度,使用下面的代码计算距离,您可以估计要添加到字符串的缩放级别。这些距离是通过大量测试来估计的。我已经安装并测试了这段代码。作品完美。享受。
调用此函数...
ps 将 $td2 添加到原始地图字符串的末尾。请原谅变量名称。有时它们是有道理的:)这就是 PHP。
First I want to THANK Jason Gennaro for an amazing idea with his JS alternative! Unfortunately, this idea assumes you have a 'zoom' level set on each map. If, as in my case, I was letting google(sic) adjust the map size itself, I came up with a modification/addition to Jason's code. If you want to use his idea, but want the maps to size properly around 2 locations, using the lat/long of each location, using the code below to calculate distance, you can estimate a zoom level to add to the string. These distances are somewhat estimated with a lot of testing. I have installed and tested this code. Works perfect. Enjoy.
Call this function with...
p.s. Add $td2 to the end of your original map string. Pardon the variable names. Sometimes they make sense :) This is PHP.