Extract lat/lng from Toast and save directly to address
Toast provides latitude/longitude in the location object. Extract in analyzeMenuUrl.cfm and pass through to saveWizard.cfm, which now includes lat/lng in the address INSERT. Skips the background Nominatim geocode when coordinates are already available. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
9225a53eee
commit
2f9bb2b869
2 changed files with 19 additions and 7 deletions
|
|
@ -1078,6 +1078,10 @@
|
||||||
<cfif structKeyExists(loc, "phone") AND NOT isNull(loc.phone)>
|
<cfif structKeyExists(loc, "phone") AND NOT isNull(loc.phone)>
|
||||||
<cfset toastBusiness["phone"] = loc.phone>
|
<cfset toastBusiness["phone"] = loc.phone>
|
||||||
</cfif>
|
</cfif>
|
||||||
|
<cfif structKeyExists(loc, "latitude") AND isNumeric(loc.latitude) AND structKeyExists(loc, "longitude") AND isNumeric(loc.longitude)>
|
||||||
|
<cfset toastBusiness["latitude"] = loc.latitude>
|
||||||
|
<cfset toastBusiness["longitude"] = loc.longitude>
|
||||||
|
</cfif>
|
||||||
</cfif>
|
</cfif>
|
||||||
<cfif structKeyExists(restaurant, "brandColor") AND NOT isNull(restaurant.brandColor)>
|
<cfif structKeyExists(restaurant, "brandColor") AND NOT isNull(restaurant.brandColor)>
|
||||||
<cfset toastBusiness["brandColor"] = replace(restaurant.brandColor, "##", "")>
|
<cfset toastBusiness["brandColor"] = replace(restaurant.brandColor, "##", "")>
|
||||||
|
|
|
||||||
|
|
@ -201,26 +201,34 @@ try {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if lat/lng provided (e.g. from Toast)
|
||||||
|
bizLat = structKeyExists(biz, "latitude") && isNumeric(biz.latitude) ? biz.latitude : 0;
|
||||||
|
bizLng = structKeyExists(biz, "longitude") && isNumeric(biz.longitude) ? biz.longitude : 0;
|
||||||
|
|
||||||
queryTimed("
|
queryTimed("
|
||||||
INSERT INTO Addresses (Line1, City, StateID, ZIPCode, UserID, AddressTypeID, AddedOn)
|
INSERT INTO Addresses (Line1, City, StateID, ZIPCode, UserID, AddressTypeID, Latitude, Longitude, AddedOn)
|
||||||
VALUES (:line1, :city, :stateID, :zip, :userID, :typeID, NOW())
|
VALUES (:line1, :city, :stateID, :zip, :userID, :typeID, :lat, :lng, NOW())
|
||||||
", {
|
", {
|
||||||
line1: len(addressLine1) ? addressLine1 : "Address pending",
|
line1: len(addressLine1) ? addressLine1 : "Address pending",
|
||||||
city: len(city) ? city : "",
|
city: len(city) ? city : "",
|
||||||
stateID: { value = stateID > 0 ? stateID : javaCast("null", ""), cfsqltype = "cf_sql_integer", null = stateID == 0 },
|
stateID: { value = stateID > 0 ? stateID : javaCast("null", ""), cfsqltype = "cf_sql_integer", null = stateID == 0 },
|
||||||
zip: len(zip) ? zip : "",
|
zip: len(zip) ? zip : "",
|
||||||
userID: userId,
|
userID: userId,
|
||||||
typeID: 2
|
typeID: 2,
|
||||||
|
lat: { value = bizLat != 0 ? bizLat : javaCast("null", ""), cfsqltype = "cf_sql_decimal", null = bizLat == 0 },
|
||||||
|
lng: { value = bizLng != 0 ? bizLng : javaCast("null", ""), cfsqltype = "cf_sql_decimal", null = bizLng == 0 }
|
||||||
}, { datasource: "payfrit" });
|
}, { datasource: "payfrit" });
|
||||||
|
|
||||||
qNewAddr = queryTimed("SELECT LAST_INSERT_ID() as id", {}, { datasource: "payfrit" });
|
qNewAddr = queryTimed("SELECT LAST_INSERT_ID() as id", {}, { datasource: "payfrit" });
|
||||||
addressId = qNewAddr.id;
|
addressId = qNewAddr.id;
|
||||||
response.steps.append("Created address record (ID: " & addressId & ")");
|
response.steps.append("Created address record (ID: " & addressId & ")");
|
||||||
|
|
||||||
// Auto-geocode address in background
|
// Auto-geocode in background only if lat/lng not already provided
|
||||||
thread action="run" name="geocode_#addressId#" addressId=addressId {
|
if (bizLat == 0 || bizLng == 0) {
|
||||||
include template="/api/inc/geocode.cfm";
|
thread action="run" name="geocode_#addressId#" addressId=addressId {
|
||||||
geocodeAddressById(attributes.addressId);
|
include template="/api/inc/geocode.cfm";
|
||||||
|
geocodeAddressById(attributes.addressId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get community meal type (1=provide meals, 2=food bank donation)
|
// Get community meal type (1=provide meals, 2=food bank donation)
|
||||||
|
|
|
||||||
Reference in a new issue