Generation

generate functionSat, 12 Nov 2022

Returns slippy map tiles which are at least partially covered by a circle with given position and radius.

void getMapTilesInCircle(double lat, double lng, double radius) { // Find the degree span of lat/lng/radius double lat_span = radius / (111.1 * 1000.0); // 111.1 km per degree of latitude double lng_span = radius / (111.1 * 1000.0); // 111.1 km per degree of longitude // Find the tile for the current position int cur_tile_x = (int)Math.Floor( (lng + 180.0)/ 360.0 * Math.Pow(2, zoom) ); int cur_tile_y = (int)Math.Floor( (1.0 - Math.Log(Math.Tan(lat * Math.PI/180.0) + 1.0 / Math.Cos(lat * Math.PI/180.0)) / Math.PI) / 2.0 * Math.Pow(2, zoom) ); // Find the tile for the north-west corner of the circle int north_west_tile_x = (int)

Want to kickstart your project?Use the new AI Studio to create your code