static void generateAndOutputMapcodes(double lat, double lon, int iShowError, int extraDigits, int useXYZ) { enum Territory context = TERRITORY_NONE; while (lon > 180.0) { lon -= 360.0; } while (lon < -180.0) { lon += 360.0; } while (lat > 90.0) { lat -= 180.0; } while (lat < -90.0) { lat += 180.0; } Mapcodes mapcodes; const int nrResults = encodeLatLonToMapcodes(&mapcodes, lat, lon, context, extraDigits); if (nrResults <= 0) { if (iShowError) { fprintf(stderr, "error: cannot encode lat=%.20g, lon=%.20g)\n", lat, lon); exit(NORMAL_ERROR); } } if (useXYZ) { double x; double y; double z; convertLatLonToXYZ(lat, lon, &x, &y, &z); printf("%d %.20g %.20g %.20g %.20g %.20g\n", nrResults, lat, lon, x, y, z); } else { printf("%d %.20g %.20g\n", nrResults, lat, lon); } for (int j = 0; j < nrResults; ++j) { const char *foundMapcode = mapcodes.mapcode[j]; // Output result line. printf("%s\n", foundMapcode); // Self-checking code to see if encoder produces this Mapcode for the lat/lon. if (selfCheckEnabled) { selfCheckLatLonToMapcode(lat, lon, foundMapcode, extraDigits); selfCheckMapcodeToLatLon(foundMapcode, lat, lon); } } // Add empty line. printf("\n"); if (nrResults > largestNrOfResults) { largestNrOfResults = nrResults; latLargestNrOfResults = lat; lonLargestNrOfResults = lon; } totalNrOfResults += nrResults; }
static void generateAndOutputMapcodes(double lat, double lon, int iShowError, int extraDigits, int useXYZ) { char *results[2 * MAX_NR_OF_MAPCODE_RESULTS]; int context = 0; while (lon > 180.0) { lon -= 360.0; } while (lon < -180.0) { lon += 360.0; } while (lat > 90.0) { lat -= 180.0; } while (lat < -90.0) { lat += 180.0; } #ifdef LIMIT_TO_MICRODEGREES { // Need to truncate lat/lon to microdegrees. long lon32 = lon * 1000000.0; long lat32 = lat * 1000000.0; lon = (lon32 / 1000000.0); lat = (lat32 / 1000000.0); } #endif const int nrResults = encodeLatLonToMapcodes_Deprecated(results, lat, lon, context, extraDigits); if (nrResults <= 0) { if (iShowError) { fprintf(stderr, "error: cannot encode lat=%.12g, lon=%.12g)\n", lat, lon); exit(NORMAL_ERROR); } } if (useXYZ) { double x; double y; double z; convertLatLonToXYZ(lat, lon, &x, &y, &z); printf("%d %.12g %.12g %.12g %.12g %.12g\n", nrResults, lat, lon, x, y, z); } else { printf("%d %.12g %.12g\n", nrResults, lat, lon); } for (int j = 0; j < nrResults; ++j) { const char *foundMapcode = results[(j * 2)]; const char *foundTerritory = results[(j * 2) + 1]; // Output result line. printf("%s %s\n", foundTerritory, foundMapcode); // Self-checking code to see if encoder produces this Mapcode for the lat/lon. if (selfCheckEnabled) { selfCheckLatLonToMapcode(lat, lon, foundTerritory, foundMapcode, extraDigits); selfCheckMapcodeToLatLon(foundTerritory, foundMapcode, lat, lon); } } // Add empty line. printf("\n"); if (nrResults > largestNrOfResults) { largestNrOfResults = nrResults; latLargestNrOfResults = lat; lonLargestNrOfResults = lon; } totalNrOfResults += nrResults; }