To set the default map location in the wagtailgeowidget
package, you can define the GEO_WIDGET_DEFAULT_LOCATION
setting in your Django settings file.
Here is an example of how to do this:
GEO_WIDGET_DEFAULT_LOCATION = {"lat": 50.5230, "lng": -4.6558}
This will set the default map location to the coordinates 50.5230° N, 4.6558° W (Bodmin, Cornwall, United Kingdom).
The GEO_WIDGET_DEFAULT_LOCATION
setting should be a dictionary with keys 'lat'
and 'lng'
representing the latitude and longitude, respectively. The values should be float values.
You can also set the default map location dynamically based on the value of a field in your model by defining a callable as the value of the GEO_WIDGET_DEFAULT_LOCATION
setting.
Here's an example of how to do this:
from django.conf import settings
def get_default_location():
# Code to retrieve default location from model goes here
return {"lat": 50.5230, "lng": -4.6558}
GEO_WIDGET_DEFAULT_LOCATION = get_default_location
This will set the default map location to the value returned by the get_default_location
function.