How to generate tile quadkeys between a set of latitude/longitude coordinates
-
Thursday, February 09, 2012 5:36 PM
Hello,
I am trying to create an algorithm that could generate all the tile quadkeys at a certain zoom level (say, 13-20) between latitude and longitude coordinates. Let's say I have the top right coordinates, top left, bottom left, and bottom right. How can I generate the tile quadkeys in between?
Any help would be appreciated! Thanks
- Moved by Richard_BrundrittMicrosoft Employee, Owner Saturday, March 10, 2012 1:24 PM (From:Bing Maps: Map Control and Web services Development)
All Replies
-
Thursday, February 09, 2012 7:15 PM
From the sample code attached to the "Bing Map Tile System" http://msdn.microsoft.com/en-us/library/bb259689.aspx
Use the following in this order:
1. LatLongToPixelXY()
2. PixelXYToTileXY()
3. TileXYToQuadKey()
-
Thursday, February 09, 2012 7:35 PMModerator
All the calculations you need are given here: http://msdn.microsoft.com/en-us/library/bb259689.aspx
Quadkeys are just an alternate way of referencing tiles as are defined under the x/y/z referencing system. I find it much easier to work in x/y/z because then, say, you know the distance covered by each tile at a given zoom level and calculate that you need 10 tiles across and 8 tiles down to fill the area - so iterate through the x and y identifiers by the required amount. You can then always convert from x/y/z to quadkey if needed.
Why/what language are you writing this algorithm in? I've probably got some Python code lying around that does it.
twitter: @alastaira blog: http://alastaira.wordpress.com/
- Marked As Answer by dybo Tuesday, February 14, 2012 2:12 PM
-
Friday, February 10, 2012 3:44 PM
Thanks for the replies!
I am writing it in C# (for wp7). I know python though.
So if I understand correctly, I can convert the lat/longs into PixelX/Ys, convert those into TileX/Ys. Then i just do 2 foreach loops to interate through the X and Ys and increment them by one during each interation? I can then convert them back to quadkeys if necessary.
-
Friday, February 10, 2012 4:20 PMModerator
So if I understand correctly, I can convert the lat/longs into PixelX/Ys, convert those into TileX/Ys. Then i just do 2 foreach loops to interate through the X and Ys and increment them by one during each interation? I can then convert them back to quadkeys if necessary.
Bingo.
Why would you want to do that on a WP7 device though? I assumed that you were trying to generate some sort of tilecache on a server..
twitter: @alastaira blog: http://alastaira.wordpress.com/
-
Tuesday, February 14, 2012 2:12 PMOh, I meant I am making an wp7 application, but this function would be server-side

