Update edit_qr_code.html geodata
This commit is contained in:
+49
-42
@@ -841,56 +841,63 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function geocodeAddress(address) {
|
function geocodeAddress(address) {
|
||||||
const geocodeBtn = document.getElementById('geocodeBtn');
|
const geocodeBtn = document.getElementById('geocodeBtn');
|
||||||
const statusDiv = document.getElementById('coordinateStatus');
|
const statusDiv = document.getElementById('coordinateStatus');
|
||||||
|
|
||||||
// Show loading state
|
// Show loading state
|
||||||
geocodeBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Getting Coordinates...';
|
geocodeBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Getting Coordinates...';
|
||||||
geocodeBtn.disabled = true;
|
geocodeBtn.disabled = true;
|
||||||
|
|
||||||
showStatus('info', 'Getting coordinates from address...');
|
showStatus('info', 'Getting coordinates from address...');
|
||||||
|
|
||||||
const geocodeUrl = `https://api.opencagedata.com/geocode/v1/json?q=${encodeURIComponent(address)}&key=b0e9dd83c98e4cfebc6a9ef1d83f5a6e&limit=1&countrycode=my&language=en`;
|
// Use backend API instead of OpenCage
|
||||||
|
fetch('/api/geocode', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
'address': address
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
console.log('Geocoding response:', data);
|
||||||
|
|
||||||
fetch(geocodeUrl)
|
if (data.success && data.data) {
|
||||||
.then(response => response.json())
|
const result = data.data;
|
||||||
.then(data => {
|
const lat = result.latitude;
|
||||||
console.log('Geocoding response:', data);
|
const lng = result.longitude;
|
||||||
|
const accuracy = result.accuracy || 'medium';
|
||||||
|
|
||||||
if (data.results && data.results.length > 0) {
|
// Update coordinates data
|
||||||
const result = data.results[0];
|
coordinatesData = {
|
||||||
const lat = result.geometry.lat;
|
latitude: lat,
|
||||||
const lng = result.geometry.lng;
|
longitude: lng,
|
||||||
const confidence = result.confidence || 0;
|
accuracy: accuracy
|
||||||
|
};
|
||||||
|
|
||||||
// Update coordinates data
|
updateCoordinatesDisplay();
|
||||||
coordinatesData = {
|
updateHiddenFields();
|
||||||
latitude: lat,
|
|
||||||
longitude: lng,
|
|
||||||
accuracy: confidence >= 8 ? 'high' : confidence >= 5 ? 'medium' : 'low'
|
|
||||||
};
|
|
||||||
|
|
||||||
updateCoordinatesDisplay();
|
showStatus('success', `Coordinates updated successfully! Accuracy: ${accuracy}`);
|
||||||
updateHiddenFields();
|
|
||||||
|
|
||||||
const confidenceText = confidence >= 8 ? 'high' : confidence >= 5 ? 'medium' : 'low';
|
console.log('✓ Coordinates updated:', coordinatesData);
|
||||||
showStatus('success', `Coordinates updated successfully! Accuracy: ${confidenceText}`);
|
} else {
|
||||||
|
const errorMessage = data.message || 'Could not find coordinates for this address. Please check the address and try again.';
|
||||||
console.log('✓ Coordinates updated:', coordinatesData);
|
showStatus('error', errorMessage);
|
||||||
} else {
|
}
|
||||||
showStatus('error', 'Could not find coordinates for this address. Please check the address and try again.');
|
})
|
||||||
}
|
.catch(error => {
|
||||||
})
|
console.error('Geocoding error:', error);
|
||||||
.catch(error => {
|
showStatus('error', 'Failed to get coordinates. Please try again.');
|
||||||
console.error('Geocoding error:', error);
|
})
|
||||||
showStatus('error', 'Failed to get coordinates. Please try again.');
|
.finally(() => {
|
||||||
})
|
// Reset button state
|
||||||
.finally(() => {
|
geocodeBtn.innerHTML = '<i class="fas fa-search-location"></i> Update Coordinates';
|
||||||
// Reset button state
|
geocodeBtn.disabled = false;
|
||||||
geocodeBtn.innerHTML = '<i class="fas fa-search-location"></i> Update Coordinates';
|
});
|
||||||
geocodeBtn.disabled = false;
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateCoordinatesDisplay() {
|
function updateCoordinatesDisplay() {
|
||||||
const latDisplay = document.getElementById('latitudeDisplay');
|
const latDisplay = document.getElementById('latitudeDisplay');
|
||||||
|
|||||||
Reference in New Issue
Block a user