from typing import Tuple
from typing import Optional
import logging


def extract_coordinates(url: str) -> Tuple[Optional[float], Optional[float]]:
    """Given Google maps url with coordinates in a query string extract latitude and longitude"""
    try:
        coordinates = url.split('q=')[-1]
        y, x = [coor.strip() for coor in coordinates.split(',')]
    except AttributeError:
        return None, None
    try:
        lat = float(y)
    except ValueError as e:
        logging.error(f'{e} {y}')
        lat = None # type: ignore
    try:
        lon = float(x)
    except ValueError as e:
        logging.error(f'{e} {x}')
        lon = None # type: ignore
    return lat, lon