import requests


def get_geo_coordinates_from_google(location_address: str, connection_params: dict):
    """
    Method to geo-code human readable address into latitudes and longitude codes using Google API.

    :param location_address: Physical address to geocode
    :param connection_params: Google API credentials for authorisation
    :return : Geocode information for the location
    """

    base_url = 'https://maps.googleapis.com/maps/api/geocode'
    endpoint = '{}/{}?address={}&key={}'.format(
        base_url,
        connection_params['output_format'],
        location_address,
        connection_params['api_key']
    )

    # make the GET request
    results = requests.get(endpoint).json()
    # print(address, results)

    # check if codes were successfully obtained or not
    if results['status'] == 'ZERO_RESULTS':
        return None

    location = results['results'][0]['geometry']['location']
    return {
        'longitude': location['lng'],
        'latitude': location['lat']
    }