Replies: 1 comment
-
I ended up pulling django-location-field from the project, and just coded it directly, here is the relevant section. // Add drag end event listener
marker.addListener("dragend", () => {
const position = marker.position;
const latLng = { lat: position.lat, lng: position.lng };
if (ifDebug) {
console.log('Marker dragged to:', latLng);
}
// Recenter the map to the new position
map.setCenter(latLng);
// Geocode the new position to get the address
geocoder.geocode({ location: latLng }, (results, status) => {
if (status === "OK") {
if (results[0]) {
const newAddress = results[0].formatted_address;
if (ifDebug) {
console.log('New address:', newAddress);
}
// Update the address field
document.getElementById('id_address').value = newAddress;
} else {
console.warn('No results found');
}
} else {
console.error('Geocoder failed due to:', status);
}
});
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I was expecting the base field ('city' in the docs) to update if the marker was moved on the map, but it doesn't do that.
I though I could add a script to my template that would "hook" into the existing map and then add code to update my base field ('location' in my app). But it doesn't find the existing map and creates a new one.
How can can I hook into the existing map, or is there a better way to simply update the base location field to update after the pin is dragged?
Beta Was this translation helpful? Give feedback.
All reactions