Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 14 December 2012 - 07:28 AM
Posted 17 December 2012 - 12:45 AM
I'd like to help with even a basic sanity test to know if the calculations were correct, but I can't seem to find the formula in their documentation in the time that I have. Perhaps you could provide a more specific link to that heading, or quote it for us?Hi there,
I'm using Google maps static API and I need to know how to get the world-size dimensions of the returned image.
I've used the formula they give in their online documentation here: https://developers.g...ion/staticmaps/ but the values returned are roughly 2.5x what they should be.
the formula is:
resolution = 256 * pow(2, zoom_level)
I then put this over the size of the world circumference (i.e. 40,075km) and then multiple by the resolution of the returned image.
size = (40,075,000 / (256 * pow(2, zoom_level)) * image_res
In my example the zoom level is 15 and image res is 1024. The value returned is 4891.96.. but it should really be closer to 1750,00 (judging by the features in the image).
Any ideas?
Thanks.
Posted 17 December 2012 - 03:49 AM
Posted 18 December 2012 - 09:18 PM
Basically, this says that the pixel coordinate is the world coordinate times two to the power indicated by the zoom level.Pixel Coordinates
World coordinates reflect absolute locations on a given projection, but we need to translate these into pixel coordinates to determine the "pixel" offset at a given zoom level. These pixel coordinates are calculated using the following formula:
pixelCoordinate = worldCoordinate * 2^zoomLevel
From the above equation, note that each increasing zoom level is twice as large in both the x and y directions. Therefore, each higher zoom level contains four times as much resolution as the preceding level. For example, at zoom level 1, the map consists of 4 256x256 pixels tiles, resulting in a pixel space from 512x512. At zoom level 19, each x and y pixel on the map can be referenced using a value between 0 and 256 * 2^19
Because we based world coordinates on the map's tile size, a pixel coordinates' integer part has the effect of identifying the exact pixel at that location in the current zoom level. Note that for zoom level 0, the pixel coordinates are equal to the world coordinates.
Note that by dividing the pixel coordinates by the tile size and taking the integer parts of the result, you produce as a by-product the tile coordinate at the current zoom level.
Posted 20 December 2012 - 03:52 AM
Posted 20 December 2012 - 12:05 PM
Posted 20 December 2012 - 12:15 PM
Yeah, that would do it. It says:Ok, the problem was that I was converting the easting and northing values using a UTM projection, whereas Google maps uses traditional Mercator projection. This is what was causing the misalignment. I changed it to use Mercator and almost everything works now, the equation I stated above calculates correct tile sizes.
But I now have another problem... apparently UTM uses an ellipsoid model of the earth as opposed to a spherical model that Mercator uses which means that northing values are offset by a specific amount now apparently 200+ meters.
So, this may mean that it cuts off the top and bottom 85 degrees to make the map square, which would account for the vertical offset. I might be reading that wrong, but either way, I'm pretty sure that this paragraph explains the phenomenon.Note that a Mercator projection has a finite width longitudinally but an infinite height latitudinally. We "cut off" base map imagery utilizing the Mercator projection at approximately +/- 85 degrees to make the resulting map shape square, which allows easier logic for tile selection. Note that a projection may produce world coordinates outside the base map's usable coordinate space if you plot very near the poles, for example.
Posted 20 December 2012 - 01:45 PM
Posted 20 December 2012 - 06:45 PM
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.