import requests


def _make_geocoding_api_request(address, mode="json"):
    """
    get latitude and longitude from some address.
    See this page for more info:
    https://developers.google.com/maps/documentation/geocoding/intro

    Examples:

    .. code-block:: python

        from support.weather import get_lat_lon

        res = _make_geocoding_api_request("Abu Dhabi").json()
        if res["status"] == "OK":
            print(res["results"][0]["geometry"]["location"]["lat"],
                  res["results"][0]["geometry"]["location"]["lng"])

    Args:
        address (str): Some address. Could be the name of a city,
            or a specific street address.
    Returns:
        requests.Response
    """
    template = "https://maps.googleapis.com/maps/api/geocode/{}?{}"
    params = []
    address_str = "address={}".format(address.replace(" ","+"))
    params.append(address_str)
    request_url = template.format(mode, ",".join(params))
    resp = requests.get(request_url)
    return resp