在 Jquery 中使用 Mapquest API 获取附近的医院

发布于 2025-01-11 10:01:09 字数 936 浏览 0 评论 0原文

我正在尝试根据用户位置获取附近的医院。我已经使用 Mapquest 生成结果。但是我的代码似乎不起作用并返回 0 响应。

var lat = 0;
var lon = 0;

if ("geolocation" in navigator) {

navigator.geolocation.getCurrentPosition(function (position) {
lat = position.coords.latitude;
lon = position.coords.longitude;
console.log(lat, lon);
axios
  .get(
    "http://www.mapquestapi.com/search/v2/radius?key=jLSFuiva5A1AyFqzlknYnBT5OqKV83g5&origin=" +
      lat +
      "," +
      lon +
      "&radius=30&hostedData=mqap.ntpois%7Cgroup_sic_code=?%7C806202&maxMatches=25&r&ambiguities=ignore"
  )
  .then(function (response) {
    console.log(response);
  });
L.mapquest.key = "jLSFuiva5A1AyFqzlknYnBT5OqKV83g5";

// 'map' refers to a <div> element with the ID map
L.mapquest.map("map", {
  center: [lat, lon],
  layers: L.mapquest.tileLayer("map"),
  zoom: 12,
});
});
 } else {
    console.log("Browser doesn't support geolocation!");
   }

I'm trying to fetch Nearby Hospitals based on Users location. I have used Mapquest to generate the results. However my code doesn't seem to work and returns 0 responses.

var lat = 0;
var lon = 0;

if ("geolocation" in navigator) {

navigator.geolocation.getCurrentPosition(function (position) {
lat = position.coords.latitude;
lon = position.coords.longitude;
console.log(lat, lon);
axios
  .get(
    "http://www.mapquestapi.com/search/v2/radius?key=jLSFuiva5A1AyFqzlknYnBT5OqKV83g5&origin=" +
      lat +
      "," +
      lon +
      "&radius=30&hostedData=mqap.ntpois%7Cgroup_sic_code=?%7C806202&maxMatches=25&r&ambiguities=ignore"
  )
  .then(function (response) {
    console.log(response);
  });
L.mapquest.key = "jLSFuiva5A1AyFqzlknYnBT5OqKV83g5";

// 'map' refers to a <div> element with the ID map
L.mapquest.map("map", {
  center: [lat, lon],
  layers: L.mapquest.tileLayer("map"),
  zoom: 12,
});
});
 } else {
    console.log("Browser doesn't support geolocation!");
   }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ζ澈沫 2025-01-18 10:01:09

search/v2 API 旨在与自定义数据管理器 API 表一起使用。您可以使用 search/v4 API 搜索一般 POI。例如:

https://www.mapquestapi.com/search/v4/place?location=-105.08143%2C39.76938&category=sic%3A806202&sort=distance&feedback=false&key=KEY

另外,我建议从您的问题中删除您的密钥。

The search/v2 API is intended to be used with a custom Data Manager API table. You can use the search/v4 API to search general POIs. For example:

https://www.mapquestapi.com/search/v4/place?location=-105.08143%2C39.76938&category=sic%3A806202&sort=distance&feedback=false&key=KEY

Also, I recommend removing your key from your question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文