OSRM API:查找到最近的应急站的距离

问题描述 投票:0回答:0

我有一个打字稿项目,我正在尝试获取到最近的警察局的距离(后来我还添加了消防局)。我为此使用打字稿

我尝试了我在互联网上找到的这个网址:

https://router.project-osrm.org/route/v1/driving/${lon},${lat};nearest?annotations=distance&exclude=motorway,toll

但它似乎根本不起作用。

我进一步查看了文档,但我不确定应该使用哪个:route/v1/drivingnearest/v1/driving。我没有找到同时具有 (?) 的解决方案。

所以总体目标是获取我所在位置的坐标,并获取到最近的警察局和最近的消防局的距离(以公里为单位)。

例如我也尝试了以下功能:

import axios from "axios";
async function getNearestPoliceStation(
  lat: number,
  lon: number
): Promise<[number, number]> {
  try {
    console.log("input lat and lon", lat, lon);
    const url2 = `https://nominatim.openstreetmap.org/search?format=json&q=police+station&limit=1&lat=${lat}&lon=${lon}`;
    const response2 = await axios.get(url2);
    console.log(response2.data[0]);
    const nearestPoliceStation = response2.data[0];
    if (!nearestPoliceStation) {
      return [-1, -1];
    }

    const lati = parseFloat(nearestPoliceStation.lat);
    const longi = parseFloat(nearestPoliceStation.lon);

    return [lati, longi];
  } catch (error) {
    console.error(error);
    return [-1, -1];
  }
}

但是当我输入 49.85349、8.65859 纬度和经度(在德国)时,它会为我找到新泽西州最近的警察局:O(40.7007047,-75.1719147)

为此的 python 代码也会有所帮助。我使用 Google Maps API(而不是 TS 和 OSMR)在 Python 上尝试了一些测试,这也不是太简单。

python typescript google-maps-api-3 openstreetmap
© www.soinside.com 2019 - 2024. All rights reserved.