Getting nearby hospitals using Mapquest API in Jquery

123 Views Asked by At

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!");
   }
1

There are 1 best solutions below

0
MQBrian On

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.