A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://stackoverflow.com/questions/78165358/python-faster-way-to-do-geocoding-api below:

Python: faster way to do Geocoding API

It almost takes 1 mimute to convert 60 addresses to coordinates with my code. I want the result to contain address, latitude and longtitude in order. Is there other faster ways? Thanks

code:

import time
import requests
import json
import pandas as pd
import numpy as np
import string

addressList=['xxx','xx1'] #330,000 addresses in total

def get_latitude_longtitude(address, GOOGLE_PLACES_API_KEY): 
    url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' + address + '&key=' + GOOGLE_PLACES_API_KEY
    while True:
        res = requests.get(url)
        js = json.loads(res.text)

        if js['status'] != 'OVER_QUERY_LIMIT':   
            time.sleep(1) 
            break

    result = js['results'][0]['geometry']['location']
    lat = result['lat'] 
    lng = result['lng'] 

    return address, lat, lng

lst=[]
for address in addressList:
    GOOGLE_PLACES_API_KEY = 'kkkkkkk'
    res = get_latitude_longtitude(address,GOOGLE_PLACES_API_KEY)
    #print(res)
    address=res[0]
    lat=res[1]
    lng=res[2]
    lst.append(address)
    lst.append(lat)
    lst.append(lng)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4