+
// Get state info for response
qState = queryTimed("SELECT Abbreviation as StateAbbreviation, Name as StateName FROM tt_States WHERE ID = :stateId", {
stateId: { value: stateId, cfsqltype: "cf_sql_integer" }
diff --git a/api/admin/_scripts/geocode.cfm b/api/admin/_scripts/geocode.cfm
index 4c88e7a..77aa952 100644
--- a/api/admin/_scripts/geocode.cfm
+++ b/api/admin/_scripts/geocode.cfm
@@ -26,51 +26,7 @@
Address Geocoding
Auto-geocode addresses using OpenStreetMap Nominatim (free, no API key required)
-
-function geocodeAddress(addressString) {
- var result = { "success": false, "error": "" };
- if (len(trim(addressString)) EQ 0) {
- result.error = "Empty address";
- return result;
- }
-
- try {
- var httpService = new http();
- httpService.setMethod("GET");
- httpService.setUrl("https://nominatim.openstreetmap.org/search?q=" & urlEncodedFormat(addressString) & "&format=json&limit=1");
- httpService.addParam(type="header", name="User-Agent", value="Payfrit/1.0");
- httpService.setTimeout(10);
-
- var httpResult = httpService.send().getPrefix();
-
- if (httpResult.statusCode CONTAINS "200") {
- var data = deserializeJSON(httpResult.fileContent);
- if (arrayLen(data) GT 0) {
- result.success = true;
- result.lat = data[1].lat;
- result.lng = data[1].lon;
- return result;
- }
- result.error = "No results found";
- return result;
- }
- result.error = "HTTP " & httpResult.statusCode;
- return result;
- } catch (any e) {
- result.error = e.message;
- return result;
- }
-}
-
-function buildAddressString(line1, line2, city, zipCode) {
- var parts = [];
- if (len(trim(line1))) arrayAppend(parts, trim(line1));
- if (len(trim(line2))) arrayAppend(parts, trim(line2));
- if (len(trim(city))) arrayAppend(parts, trim(city));
- if (len(trim(zipCode))) arrayAppend(parts, trim(zipCode));
- return arrayToList(parts, ", ");
-}
-
+
diff --git a/api/businesses/update.cfm b/api/businesses/update.cfm
index ffa4b63..902cca7 100644
--- a/api/businesses/update.cfm
+++ b/api/businesses/update.cfm
@@ -111,6 +111,7 @@ try {
zip: zip,
addrID: qAddr.ID
}, { datasource: "payfrit" });
+ geocodeAddrId = qAddr.ID;
} else {
// Create new address
queryTimed("
@@ -123,8 +124,18 @@ try {
zip: zip,
bizID: businessId
}, { datasource: "payfrit" });
+ qNewAddr = queryTimed("SELECT LAST_INSERT_ID() as id", {}, { datasource: "payfrit" });
+ geocodeAddrId = qNewAddr.id;
}
+ // Auto-geocode address in background
+
+