urlquery-stringmapquest

Is it possible to search for multiple categories in a single MapQuest API call?


I am using the MapQuest API to search for certain types of businesses within a 1 mile radius of a given location.

For example, to find grocery stores in downtown New York, I would use this link:

https://www.mapquestapi.com/search/v2/radius?origin=40.75,-73.98&radius=1&units=m&maxMatches=20&hostedData=mqap.ntpois|group_sic_code=?|541105&key=[API_KEY]

And to find restaurants, I would use this link:

https://www.mapquestapi.com/search/v2/radius?origin=40.75,-73.98&radius=1&units=m&maxMatches=20&hostedData=mqap.ntpois|group_sic_code=?|581208&key=[API_KEY]

You'll notice that both calls are the exact same except the group_sic_code was changed from "541105" (grocery stores) to "581208" (restaurants).

If possible, I would like to get the results from both queries in a single call.

After better understanding the syntax, it looks like it's a simple SQL query, so I thought I could just change it from a simple EQUALS statement to an IN statement like this:

hostedData=mqap.ntpois|group_sic_code IN (?)|541105,581208

But I get the following error:

Invalid number of parameters, expected 1, got 2

Is my request even possible? Or do I have to make 1 call for each category? I have over 50 categories I'd like to query, so I'd like to consolidate if possible.

Thanks in advance!


Solution

  • Given the extraCriteria is supposedly evaluated as SQL, you could try something like the following

    hostedData%3Dmqap.ntpois%7Cgroup_sic_code%20IN(%3F%2C%3F)%7C541105%2C581208
    

    (decoded)

    hostedData=mqap.ntpois|group_sic_code IN(?,?)|541105,581208
    

    However there appears to be a lot of string-splitting going on and it may not like the comma in (?,?).

    As an alternative, try a simple OR statement

    hostedData%3Dmqap.ntpois%7Cgroup_sic_code%3D%3F%20OR%20group_sic_code%3D%3F%7C541105%2C581208
    

    (decoded)

    hostedData=mqap.ntpois|group_sic_code=? OR group_sic_code=?|541105,581208