Skip to content

Commit

Permalink
add latitude and longitude to location
Browse files Browse the repository at this point in the history
Signed-off-by: frank-zsy <[email protected]>
  • Loading branch information
frank-zsy committed Nov 5, 2023
1 parent db65eb9 commit 0f0c46d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/cron/tasks/update_location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const task: Task = {
\`country\` LowCardinality(String),
\`administrative_area_level_1\` LowCardinality(String),
\`administrative_area_level_2\` LowCardinality(String),
\`locality\` LowCardinality(String)
\`locality\` LowCardinality(String),
\`longitude\` Float32,
\`latitude\` Float32
)
ENGINE = ReplacingMergeTree
ORDER BY (location)
Expand Down Expand Up @@ -56,12 +58,17 @@ const task: Task = {
}
} else {
ret.status = 'normal';
const data = resp.json.results[0];
['country', 'administrative_area_level_1', 'administrative_area_level_2', 'locality'].forEach(k => {
const value = resp.json.results[0].address_components.find(i => i.types[0] === k);
const value = data.address_components.find(i => i.types[0] === k);
if (value) {
ret[k] = value.long_name;
}
});
if (data?.geometry?.location) {
ret.latitude = data.geometry.location.lat;
ret.longitude = data.geometry.location.lng;
}
}
resolve(ret);
});
Expand Down

0 comments on commit 0f0c46d

Please sign in to comment.