在 Jquery 中使用 Mapquest API 获取附近的医院
我正在尝试根据用户位置获取附近的医院。我已经使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.