0


I want to combine responses of two or more APIs. I havent made API before so would prefer something which is available online to combine two APIs.
For example, if one API lists the names of cities in California and other lists names of cities in Texas, then how can I combine them in a way that just one API call returns list of cities of California as well as Texas?
Do you guys know if something like this is available online? Like any tool or something?
Thanks in advance for your help.
I want following structure OR an API that has the following structure. Any API having this structure is fine, it just should have a range of locations

results:
[
California :
{
county:Orange county
lat:
long:
},
{
county:santa clara county
lat:
long:
},
{
county:LA county
lat:
long:
},
{
county:long beach county
lat:
long:
},
],
Texas:
{
county:Orange county
lat:
long:
},
{
county:Orange county
lat:
long:
},
{
county:Orange county
lat:
long:
},
{
county:Orange county
lat:
long:
},
{
county:Orange county
lat:
long:
},
],
New Jersey[
{
county:Orange county
lat:
long:
}

]
]
jmunsch
  • 22,771
  • 11
  • 93
  • 114
iCoder
  • 53
  • 1
  • 8
  • I don't think there is a tool for that. You can combine e.g. two rest calls in your backend and implement your own rest endpont (api) but this is not a good architecture. Why would you like to do this? have you specific apis you want to combine? – Simon Schnell Dec 23 '16 at 08:26
  • so you want the country name, lat and long? and which is your parameter? where to determine how many results you get? – Simon Schnell Dec 23 '16 at 08:40
  • Basically I want an array of States and each State should have array of cities or counties inside it, which has a dictionary of lat, long, name, etc. – iCoder Dec 23 '16 at 08:42
  • For example, this Walmart Store Locator API(http://api.walmartlabs.com/v1/stores?format=json&city=Fullerton&apiKey=q6u2eghwtf4mb956aj52hqrb) has the response which has an array of locations. Similarly I want that for several cities combined into one API so I just need to call one API from the front-end. – iCoder Dec 23 '16 at 08:45
  • have a look over [here](https://www.blackbaud.com/files/support/guides/infinitytechref/Content/RESTAPI/3-0/CountryAndStateApi.htm) you know how to work with `REST`? which program language you use? – Simon Schnell Dec 23 '16 at 08:45
  • I use Swift. I want it for a Mobile App. – iCoder Dec 23 '16 at 08:47
  • @iCoder See: http://meta.stackexchange.com/questions/22186/how-do-i-format-my-code-blocks not sure about the `
    ` tags in your question text
    – jmunsch Dec 23 '16 at 09:02

1 Answers1

0

It can be done by making two requests with like so to openstreetmaps using javascript in the dev console, or in a <script> tag, you could also use curl or python and requests.get, or whatever language you prefer:

Promise.all([
    fetch("http://nominatim.openstreetmap.org/search/?city=San%20Francisco&state=California&format=json"), 
    fetch("http://nominatim.openstreetmap.org/search/?city=Austin&state=Texas&format=json")
])
.then(values => {
  return Promise.all(values.map(v=>v.text()))
})
.then(values => {
  values.map(v=>{console.log(v)})
})
.catch(e => {console.warn(e)})

Output:

"[
      {
        "place_id": "158675742",
        "licence": "Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright",
        "osm_type": "relation",
        "osm_id": "111968",
        "boundingbox": [
          "37.6403143",
          "37.9298443",
          "-123.1738249",
          "-122.2817799"
        ],
        "lat": "37.7792808",
        "lon": "-122.4192362",
        "display_name": "San Francisco, San Francisco City and County, California, United States of America",
        "class": "place",
        "type": "city",
        "importance": 0.99836369596997,
        "icon": "http://nominatim.openstreetmap.org/images/mapicons/poi_place_city.p.20.png"
      }
    ]"

    "[
  {
    "place_id": "158900509",
    "licence": "Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright",
    "osm_type": "relation",
    "osm_id": "113314",
    "boundingbox": [
      "30.0986648",
      "30.516863",
      "-97.9383829",
      "-97.5614889"
    ],
    "lat": "30.2711286",
    "lon": "-97.7436994",
    "display_name": "Austin, Travis County, Texas, United States of America",
    "class": "place",
    "type": "city",
    "importance": 0.8589403884382,
    "icon": "http://nominatim.openstreetmap.org/images/mapicons/poi_place_city.p.20.png"
  }
]"

Another option is to use:

Example from docs:

from geopy.geocoders import GeocoderDotUS
geolocator = GeocoderDotUS(format_string="%s, Cleveland OH")
address, (latitude, longitude) = geolocator.geocode("11111 Euclid Ave")
print(address, latitude, longitude)
11111 Euclid Ave, Cleveland, OH 44106 41.506784 -81.608148

For swift it looks like this might work, but its just a get request, so I am not sure how complicated the wrapper to openstreetmaps needs to be:

or see:

Community
  • 1
  • 1
jmunsch
  • 22,771
  • 11
  • 93
  • 114