Following code is to calculate pixel and tile coordinates of a location. It works fine using 256px tiles. But if you use 512px tile world and pixel coordinates works fine but tile coordinates does not change which is not possible.
256px tile size
Chicago, IL
LatLng: (41.85, -87.64999999999998)
Zoom level: 15
World Coordinate: (65.67111111111113, 95.17492654697409)
Pixel Coordinate: (2151910, 3118691)
Tile Coordinate: (8405, 12182) <-------- SAME ----------------
512px tile size
Chicago, IL
LatLng: (41.85, -87.64999999999998)
Zoom level: 15
World Coordinate: (131.34222222222226, 190.34985309394818)
Pixel Coordinate: (4303821, 6237383)
Tile Coordinate: (8405, 12182) <--------- SAME ---------------
This is the code that calculates tile coordinates
var tileCoordinate = new google.maps.Point(
Math.floor(worldCoordinate.x * scale / TILE_SIZE),
Math.floor(worldCoordinate.y * scale / TILE_SIZE));
I tried to modify it but i believe if coordinate is close to the edge of the tile it may give wrong tile coordinates (like the tile next to it). May be it's because of too much divisions and roundings.
var tileCoordinate = new google.maps.Point(
Math.floor(worldCoordinate.x * scale / (TILE_SIZE * (TILE_SIZE / 256))),
Math.floor(worldCoordinate.y * scale / (TILE_SIZE * (TILE_SIZE / 256))));
Anyone had this problem and knows the solution?
https://developers.google.com/maps/documentation/javascript/examples/map-coordinates