问题描述
我正在PHP
中开发一个Web服务,该服务获取以公里为单位的纬度,经度和半径,并生成 Google静态地图.
I'm developing a web service in PHP
that gets a latitude, longitude and a radius in kilometers and generate google static map.
我还显示了该半径范围内数据库中的所有点.
Also I display all points from my database in that radius.
我的问题是如何在Google的zoom
参数中隐藏我的radius
以确保所有点在地图上都可见?
My question is how I can covert my radius
in google's zoom
parameter to ensure that all points are visible on the map?
类似于:http://maps.googleapis.com/maps/api/staticmap?center=New+York,NY&[*THIS PARAMETER*zoom=13]&size=600x300&markers.......
推荐答案
意味着在zoomLevel 2时,地图任意方向上的像素= 256 *2²= 1024px.
Meaning that at zoomLevel 2, the pixels in any direction of a map are = 256 * 2² = 1024px.
考虑到地球的周长约为40,000公里(以缩放0表示),每个像素〜= 40,000 km/256 = 156.25 km
缩放9时,像素为131072:
1px = 40,000 km/131072 = 0.305 km ...
Taking into account that the earth has a perimeter of ~40,000 kilometers, in zoom 0, every pixel ~= 40,000 km/256 = 156.25 km
At zoom 9, pixels are 131072:
1px = 40,000 km / 131072 = 0.305 km ... and so on.
如果图像为640 x 640像素,并且正在使用缩放9,这意味着您将覆盖〜640 * 0.305〜= 195km.因此您的半径约为100公里.
每次缩放++时,半径都是一半.
If your image is 640 x 640 px,and you are using zoom 9, this means that you will cover ~ 640 * 0.305 ~= 195km. So your radius is approx 100km.
Everytime you zoom++, the radius is the half.
如果使用缩放15(1px = 0.00478km),则图像将覆盖约3km宽(半径1.5km).
If you use zoom 15 (1px = 0.00478km) your image will cover ~3km wide (radius 1.5km).
请注意,随着您向北或向南移动,实际距离会更短,而失真会更大.
Take into account that as you go further to north or south, the real distance is less, as the distortion is bigger.
您可以将zoom = Floor(log (EarthP * 2 PixMap/(256 * radius)))作为参数使用.
You could use as parameter something like zoom = Floor(log (EarthP * 2 PixMap / (256 *radius))).
- EarthP =该纬度处的地球周长(以公里为单位)
- PixMap =您将显示的地图像素
- 半径=要在图像中显示的半径(以公里为单位)
- log =以2为底的对数
- EarthP = Earth perimeter at that Latitude (in km)
- PixMap = Pixels of the map you will display
- radius = radius you want to be displayed in your image (in km)
- log = logarithm in base 2
注意:要将log 转换为常规日志,只需执行以下操作:
Floor((log(EarthP * 2 PixMap/(256 * radius)))/log 2)
note: to convert log into regular log just make this:
Floor((log (EarthP * 2 PixMap / (256 *radius)))/log 2)
这篇关于Google静态地图半径进行缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!