Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coordinates to tile pixels

I am developing a tile overlay server for google maps. I want to draw a point on a tile for a specific location. How can i convert the real world coordinates to tile pixel coordinates?

I have calculated a tile's bounds so i know if a given point is inside it. My problem is where in the tile should i draw it.

Interpolation works ok for longitude but not for latitude, which is normal for mercatoric maps.

Unfortunately my trigonometry skills are a bit rusty. Could someone give me a hint?

I am using 256x256 pixel tiles. The zoom level, x and y are also given for a tile.

like image 845
gtsouk Avatar asked Sep 04 '26 13:09

gtsouk


1 Answers

I found the answer here. I had to tweak it a bit:

var offset = 256 << (z-1) - (256 << (z-1))/Math.PI * Math.log((1 + Math.sin(lat * Math.PI / 180)) / (1 - Math.sin(lat * Math.PI / 180))) / 2;
circley = offset - 256*y;
like image 194
gtsouk Avatar answered Sep 06 '26 19:09

gtsouk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!