Default location in wagtail-geo-widget

I have successfully added a GeoAddressPanel and LeafletPanel to a Wagtail admin page using Wagtail Geo Widget. I'd like to override the default location but can't figure out how, any ideas?

This is what I have and that's working fine in the Wagtail admin:

  MultiFieldPanel(
        [
            GeoAddressPanel("address", geocoder=geocoders.NOMINATIM),
            LeafletPanel(
                "location", address_field="address"
            ),
        )

Tried some suggestion by Claude.ai, but it did not have a clue.

To override the default location in Wagtail Geo Widget, you can pass the default_latitude and default_longitude parameters to the LeafletPanel. These parameters define the default coordinates that will be displayed on the map when it is first loaded.

Here's how you can modify your code to set a default location:

from wagtailgeo.widgets import geocoders

MultiFieldPanel(
    [
        GeoAddressPanel("address", geocoder=geocoders.NOMINATIM),
        LeafletPanel(
            "location",
            address_field="address",
            default_latitude=34.0522,  # Set your default latitude
            default_longitude=-118.2437,  # Set your default longitude
            default_zoom=12,  # You can also specify a default zoom level
        ),
    ]
)

In this example, 34.0522 and -118.2437 are the latitude and longitude for Los Angeles, but you can replace them with your desired default location.

This will ensure that the map opens at your specified coordinates by default when editing the page in the Wagtail admin interface.

The default location setting is updated with adding an object {'lat': <latitude>, 'lng': <longitude> to GEO_WIDGET_DEFAULT_LOCATION in settings.py

Back to Top