openwisp/django-loci

[ux] Automatically calculate geographic coordinates or address

nemesifier opened this issue · 0 comments

When the position on the geographic map is updated:

  1. if the address field is empty we should automatically get the best address from the geographic coordinates and update the address field with the result
  2. if the address field is not empty we should ask the user if the user wants the map to be updated (for now with a simple javascript confirm dialog); If the user replies affirmatively we can do the same described in point 1

When address field is updated:

  1. If the geographic coordinates on the map are not set, we can get the geographic coordinates from the address and update the map accordingly
    2 if the geographic coordinates on the map are already set, we should ask the user if the user wants the map to be updated (for now with a simple javascript confirm dialog); If the user replies affirmatively we can do the same described in point 1

For the geocoding operations, we can use geopy.

We should implement an abstraction that allows to change the provider, trying to support at least Google Maps, Nominatim and ArcGIS in the first version fo this feature.

We should handle failures and retry, retry by default 3 times with a delay of 1 second in case of failures, the geocoding library should have a built-in implementation for this, see RateLimiter.

We will likely need the addition of a few django global settings that allow to set:

  • the chosen provider, defaults to ArcGIS
  • the API key, defaults to None
  • whether the django app may refuse to start if the testing of the geocoding operation fails, defaults to True, eg: DJANGO_LOCI_STRICT_GEOCODE_TEST
  • amount of retries after failures, default to 3
  • delay in seconds before trying again after a failure, default to 1

On startup, the app shall test an arbitrary geocoding operation (eg: get the coordinates of the address of the Python Foundation) and if it fails it will raise an ImproperlyConfigured exception if DJANGO_LOCI_STRICT_GEOCODE_TEST is True or it will log an error otherwise (using the python logging facility).

Since this app does not use django-rest-framework, the geocoding operations should be performed via a simple JSON view API that it is added to the admin as we do in django-netjsonconfig (see context_view as a reference), although the logic to perform the geocoding can be stored in a function or a class to improve reusability.

This feature needs to be documented in the README and good tests must be written for it.