reverse geocoding for contributions
This commit is contained in:
@@ -205,7 +205,7 @@ function handle_update($input) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Builds dynamic SQL Query to only update sent Fields
|
// Builds dynamic SQL Query to only update sent Fields
|
||||||
$updatable_fields = ['category', 'title', 'description', 'status'];
|
$updatable_fields = ['category', 'title', 'description', 'status', 'address'];
|
||||||
$set_clauses = [];
|
$set_clauses = [];
|
||||||
$params = [':id' => $contribution_id];
|
$params = [':id' => $contribution_id];
|
||||||
|
|
||||||
|
|||||||
@@ -448,6 +448,14 @@ function submitCreate() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Triggers Reverse Geocoding in Background
|
||||||
|
if (response.contribution_id && drawnGeometry) {
|
||||||
|
const coords = drawnGeomType === 'point' ? drawnGeometry.coordinates :
|
||||||
|
drawnGeomType === 'line' ? drawnGeometry.coordinates[0] :
|
||||||
|
drawnGeometry.coordinates[0][0];
|
||||||
|
reverseGeocode(response.contribution_id, coords[1], coords[0]);
|
||||||
|
}
|
||||||
|
|
||||||
Swal.fire('Eingereicht!', 'Ihr Beitrag wurde erfolgreich eingereicht und wird nach Prüfung durch das Moderationsteam veröffentlicht.', 'success');
|
Swal.fire('Eingereicht!', 'Ihr Beitrag wurde erfolgreich eingereicht und wird nach Prüfung durch das Moderationsteam veröffentlicht.', 'success');
|
||||||
closeCreateModal();
|
closeCreateModal();
|
||||||
loadContributions();
|
loadContributions();
|
||||||
@@ -917,6 +925,31 @@ function categoryIcon(cat) {
|
|||||||
return '<i class="fa-solid ' + cat.faIcon + '" style="color:' + cat.color + ';"></i>';
|
return '<i class="fa-solid ' + cat.faIcon + '" style="color:' + cat.color + ';"></i>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reverse Geocodes Coordinates and saves Address to Contribution via API
|
||||||
|
function reverseGeocode(contributionId, lat, lng) {
|
||||||
|
fetch('https://nominatim.openstreetmap.org/reverse?format=json&lat=' + lat + '&lon=' + lng + '&zoom=18&addressdetails=1', {
|
||||||
|
headers: { 'Accept-Language': 'de' }
|
||||||
|
})
|
||||||
|
.then(function (r) { return r.json(); })
|
||||||
|
.then(function (data) {
|
||||||
|
if (data.display_name) {
|
||||||
|
const addr = data.address || {};
|
||||||
|
const parts = [];
|
||||||
|
if (addr.road) parts.push(addr.road + (addr.house_number ? ' ' + addr.house_number : ''));
|
||||||
|
if (addr.city || addr.town || addr.village) parts.push(addr.city || addr.town || addr.village);
|
||||||
|
const shortAddress = parts.length > 0 ? parts.join(', ') : data.display_name.split(',').slice(0, 2).join(',');
|
||||||
|
|
||||||
|
// Saves Address to Database via API
|
||||||
|
apiCall({
|
||||||
|
action: 'update',
|
||||||
|
contribution_id: contributionId,
|
||||||
|
address: shortAddress
|
||||||
|
}, function () {});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(function () {});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// =====================================================================
|
// =====================================================================
|
||||||
// Block 16: Application Startup
|
// Block 16: Application Startup
|
||||||
|
|||||||
Reference in New Issue
Block a user