+#ifndef USE_MYSQL
+#ifndef USE_PGSQL
+#error One of USE_MYSQL or USE_PGSQL must be defined
+#endif
+#endif
+
+#include <math.h>
+
+/* The real maptile-for-point functionality is here */
+
+static long long internal_maptile_for_point(double lat, double lon, long long zoom)
+{
+ double scale = pow(2, zoom);
+ double r_per_d = M_PI / 180;
+ unsigned int x;
+ unsigned int y;
+
+ x = floor((lon + 180.0) * scale / 360.0);
+ y = floor((1 - log(tan(lat * r_per_d) + 1.0 / cos(lat * r_per_d)) / M_PI) * scale / 2.0);
+
+ return (x << zoom) | y;
+}
+
+#ifdef USE_MYSQL
+#ifdef USE_PGSQL
+#error ONLY one of USE_MYSQL and USE_PGSQL should be defined
+#endif
+