Dawinartor / webther

Django based simple weather web application
0 stars 0 forks source link

IP location or user GPS position #9

Closed Dawinartor closed 9 months ago

Dawinartor commented 9 months ago

Instead of default values (Bremen, Germany) get the user's current location by IP location service or use client-side JavaScript geolocation API to get location data.

Test geolocation options

REST-API functionalities

Send Geolocation

Dawinartor commented 9 months ago

JavaScript GeoLocation API successfully tested: image

Dawinartor commented 9 months ago

IP location services are either an API itself and limited to request amount or too expensive to use it in production

Dawinartor commented 9 months ago

I have no clue how to use the collected Front-End data in my utilities.py to render the correct component? Check the views.py one more time and think about how to restructure the application to collect the data, use the right component and render it the right way.

def handle_geolocation(request):
    if request.method == 'POST':
        data = json.loads(request.body)
        latitude = data.get('latitude')
        longitude = data.get('longitude')

        # Process the latitude and longitude as needed
        # For example, you can save them to a database or perform other actions
        # print(request.method, latitude, longitude)
        variable = process_geolocation(latitude, longitude)

        return JsonResponse({'status': 'success'})
    else:
        return JsonResponse({'status': 'error', 'message': 'Invalid request method'})

def process_geolocation(latitude, longitude):
    # Access latitude and longitude in this function
    # Process the data as needed
    result = f"Received latitude: {latitude} & longitude: {longitude}"
    print(result)
    return result