• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
staticVoid2

Static Maps API Image size

8 posts in this topic

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.google.com/maps/documentation/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.
0

Share this post


Link to post
Share on other sites
[quote name='staticVoid2' timestamp='1355491730' post='5010599']
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: [url="https://developers.google.com/maps/documentation/staticmaps/"]https://developers.g...ion/staticmaps/[/url] 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.
[/quote]
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?
1

Share this post


Link to post
Share on other sites
Sorry, the link I posted links to another site here: https://developers.google.com/maps/documentation/javascript/maptypes#MapCoordinates which describes the zoom levels in more detail.
0

Share this post


Link to post
Share on other sites
Let's see, first:

[quote]
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.
[/quote]
Basically, this says that the pixel coordinate is the world coordinate times two to the power indicated by the zoom level.

Later, it says:
[quote]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.[/quote]

So, say that you want to get which tile and offset the center of the world is (128, 128) at zoom level 15 (tile size 1024).
tileX = (worldX / 256) * pow(2, zoomLevel) / tileSize
tileY = (worldY / 256) * pow(2, zoomLevel) / tileSize

To get the pixel offset into that tile:
offsetX = (worldX / 256) * pow(2, zoomLevel) % tileSize
offsetY = (worldY / 256) * pow(2, zoomLevel) % tileSize

Now, I assume you are trying to get the scale of the image in physical units, or something of the like.
You could rewrite your formula a different way, to think of it from another angle.
size = (40,075,000 / pow(2, zoomLevel)) * (tileSize / 256)

Dividing the base tile's real length by the number of tiles, then converting from the base tile's scale factor (256) to yours (tileSize). Doing this calculation results in 4,891.96... which seems to make perfect sense, and I can find nothing wrong with it.

So, my other guess is that your estimation of what the distance should be is incorrect. How are you figuring it out? Are there any other applications that you can use to test it out? For starters, try using Google Maps, zoom in to level 15, ask for directions starting from one edge of the tile to the other, and check the total distance shown in the directions (try to use a highway to minimize curvature of the road). If it is closer to 4000km, then there's no problem.

Additionally, what decides the tile size?
1

Share this post


Link to post
Share on other sites
I thought I found the solution to this but I was wrong, the documentation states that for the free version the maximum image size returned is 640x640 so the calculation was slightly incorrect. Even now it is still much larger than what it should be.

The problem I'm having is that I need to request a Google/Static map which is directly adjacent to another one previously requested (so that the pixels align). I specify world coordinates in Cartesian (UTM) and I then inverse project these to get their longitude and latitude values. These are then sent to Google maps to retrieve the image. Using the formula in their documentation does not return the correct size apparently. I tried manually scaling the size parameter which meant that the tiles were spaced further apart and therefore the longitude and latitude were also, but this does not show any signs of converging to a correct alignment which makes me believe that this may be something to do with the conversion between UTM and the Mercaror projection that Google maps uses.

Can someone confirm that the coordinate system of the UTM and Mercator are the same? (after projection)

If anyone could provide some useful links to relevant material or come up with some tests I could run I would be most grateful.

Thanks.
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
[quote name='staticVoid2' timestamp='1356026747' post='5012860']
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.
[/quote]
Yeah, that would do it. It says:
[quote]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.[/quote]
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.
1

Share this post


Link to post
Share on other sites
If I take a world space coordinate (northing, easting) and project it using standard Mercator projection it will give me a different latitude/longitude pair than when I use UTM projection. Is there any way I can convert before the projection so that it gives me the same value?
0

Share this post


Link to post
Share on other sites
http://users.tpg.com.au/adslly6v/UtmGoogleStreetView.html

This site has a form that allows you to convert from UTM to coordinates usable with Google Maps. The page appears to be implemented in JavaScript, so perhaps you could read through its source to learn how it does it?
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0