This code starts by crawling the addresses that need to be converted to latitude and longitude in the'address.csv' Example of a screenshot of the file in the file:
Code Showcase
# coding=utf-8 # SPL # Time: 2020/12/20 21:15 import csv import requests import json import pandas as pd num=0 y=[] with open("address.csv", 'r') as f: # Write the file path of the address to be converted, here is the default file path (to import the file in advance) (note that it is a csv format file) r = (f, delimiter=',') for row in r: print(row[0]) #Remember to fill in the key= followed by the key to apply for the Baidu Maps development platform. url = "/v3/geocode/geo?key=**********&address=" + row[0] dat = { 'count': "1", } r = (url, data=(dat)) s = () b = s['geocodes'] for j in range(0, 10000): try: neirong1 = b[j] except: continue try: b = neirong1['location'] except: continue try: lon_lat= (',') lon=float(lon_lat[0]) lat = float(lon_lat[1]) print(lon) print(lat) except: continue num += 1 print("No." + str(num) + "Bar address translation successful.") ([row[0], lon, lat]) result = (y) = ['Address', 'Longitude', 'Latitude'] result.to_csv('Address to latitude/longitude.csv', encoding='utf-8-sig', index=False)
running result
Screenshot of the table generated after successful conversion _
To this point, this article on Python call high German API to achieve bulk address to latitude and longitude and write the function of the form of the article is introduced to this, more related Python high German API to achieve bulk address to latitude and longitude content, please search for my previous posts or continue to browse the following related articles I hope you will support me in the future more!