<jupyter_start><jupyter_text>Refresh tuto source : https://www.youtube.com/watch?v=ckPEY2KppHc<jupyter_code>import requests
import json<jupyter_output><empty_output><jupyter_text>**Integrate the Google Maps API key**<jupyter_code>api_key = ""
with open('api_key.txt') as f:
    api_key = f.readline()
    f.close
# add encoding functionalities
from urllib.parse import urlencode
data_type = "json"
endpoint = f"https://maps.googleapis.com/maps/api/geocode/{data_type}"
params = {'address':'1600 Amphitheatre Parkway, Mountain View, CA','key':api_key}
url_params = urlencode(params)# encode text into url ready data structure
sample = "https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY"

print(url_params)
url = f"{endpoint}?{url_params}"
url<jupyter_output><empty_output><jupyter_text>Function to extract longitude an latitude<jupyter_code>def extract_lat_lng(address,data_type = 'json'):
    data_type = "json"
    endpoint = f"https://maps.googleapis.com/maps/api/geocode/{data_type}"
    params = {'address':address,'key':api_key}
    url_params = urlencode(params)# encode text into url ready data structure
    url = f"{endpoint}?{url_params}"
    r = requests.get(url)
    #checking for error
    if r.status_code not in range(200,299):
        return {}
    latlng = {}
    try:
        latlng = r.json()['results'][0]['geometry']['location']
    except:
        pass
    return latlng.get('lat'), latlng.get('lng')
# Line made to delimit and display the function when (return r.json()['results'][0].keys())
extract_lat_lng("1600 Amphitheatre Parkway, Mountain View, CA")
extract_lat_lng("1600 Amphitheatre Parkway, Mountain View, CA")
from urllib.parse import urlparse, parse_qsl
to_parse = "https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key="+api_key<jupyter_output><empty_output><jupyter_text>Split URL into component Parts<jupyter_code># Split url into component part
urlparse(to_parse)
# isolate the query string
parsed_url = urlparse(to_parse)
query_string = parsed_url.query
query_string
# convert into tuples
query_tuple = parse_qsl(query_string)
print(query_tuple)
#convert into dict
query_dict = dict(query_tuple)
query_dict
# endpoint
endpoint = f"{parsed_url.scheme}://{parsed_url.netloc}{parsed_url.path}"
print(endpoint)<jupyter_output>https://maps.googleapis.com/maps/api/geocode/json
{'fraction_non_alphanumeric': 0.13152486642005753, 'fraction_numerical': 0.011919441019317715, 'mean_word_length': 6.222551928783383, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 6, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '282956', 'license': 'MIT', 'n_tokens_mistral': 876, 'n_tokens_neox': 835, 'n_words': 161, 'path': '1_Geocoding.ipynb', 'repo_name': 'chikoungoun/Google-Maps', 'size': '2433'}