Hello,
I'm using the Maps API to check the distance between two points, so I have two local.csv files and .csv coordinates.
The final goal is to know the distance of the locations for each of the coordinates.
If there are 3 locations and 2 coordinates, the expected result was to be:
Local1, Coordenacao1
Local1, Coordenacao2
Local2, Coordenacao1
Local2, Coordenacao2
Local3, Coordenacao1
Local3, Coordenacao2
But the code below is only returning the first item of coordination:
Local1, Coordenacao1
Local1, Coordenacao2
I believe the error is in using for
import googlemaps
import csv
gmaps = googlemaps.Client(key='TOKEN')
coluna_participante = 0
coluna_coordenacao = 0
entrada_local = open('arquivos/locais.csv', 'r')
entrada_coordenacao = open('arquivos/coordenacoes.csv', 'r')
saida = open('arquivos/saida.csv', 'w', newline='')
try:
ler_local = csv.reader(entrada_local)
ler_coordenacao = csv.reader(entrada_coordenacao)
escrever = csv.writer(saida)
for row in list(ler_coordenacao)[1:]:
coordenadas_coordenacao = row[coluna_coordenacao]
for row in list(ler_local)[1:]:
coordenadas_local = row[coluna_local]
distancia = gmaps.distance_matrix(coordenadas_local, coordenadas_coordenacao)
print(distancia)
finally:
entrada_local.close()
entrada_coordenacao.close()
saida.close()
I would also like to get the result in table format, in the file output.csv in the following template:
local1, distancia(1,1), distancia(1,2)
local2, distancia(2,1), distancia(2,2)
local3, distancia(3,1), distancia(1,2)
What changes should I make?