diff --git a/routingpy/routers/google.py b/routingpy/routers/google.py index d832179..07e2c2f 100644 --- a/routingpy/routers/google.py +++ b/routingpy/routers/google.py @@ -515,13 +515,21 @@ def parse_matrix_json(response): if response is None: # pragma: no cover return Matrix() - durations = [ - [destination["duration"]["value"] for destination in origin["elements"]] - for origin in response["rows"] - ] - distances = [ - [destination["distance"]["value"] for destination in origin["elements"]] - for origin in response["rows"] - ] + durations = [] + distances = [] + for row in response["rows"]: + row_durations = [] + row_distances = [] + for element in row["elements"]: + if element["status"] == "OK": + row_durations.append(element["duration"]["value"]) + row_distances.append(element["distance"]["value"]) + + else: + row_durations.append(None) + row_distances.append(None) + + durations.append(row_durations) + distances.append(row_distances) return Matrix(durations, distances, response) diff --git a/tests/test_helper.py b/tests/test_helper.py index 5ac5597..854b596 100644 --- a/tests/test_helper.py +++ b/tests/test_helper.py @@ -421,6 +421,7 @@ { "elements": [ { + "status": "OK", "distance": {"text": "225 mi", "value": 361957}, "duration": {"text": "3 hours 50 mins", "value": 13813}, }