AkrosAG / Akros-Marketplace

Apache License 2.0
3 stars 5 forks source link

Check out ZIP-code related options within Post API #83

Closed TimmyAeberli closed 2 years ago

TimmyAeberli commented 2 years ago

As a Developer I want to use an API that takes input "center-ZIP-code" and "radius" and returns a list of ZIP-codes within the specified radius around the "center-ZIP-code", in order to relate a request to possible matches.

AC1: The API needs to return ZIP-codes and optionally additional information, like canton or long & lat. AC2: The API needs to work for Switzerland. AC3: The API needs to be free or allow for a sufficient amount of free lookups. AC4: The API should be easy to use and sufficiently "secure".

TimmyAeberli commented 2 years ago

I found a decently working API (tested with Postman). However it is only offering 190 free user lookups per month. Unlimited lookups cost 9$ per month. Here is a image of the search and lookup response. image

stefanleminh commented 2 years ago

How about something like OpenRouteService or Graphhopper? Their pricing seems fair even for free tiers since they're based on the free OpenStreetMaps. You do need to get an API-Key to send requests but that shouldn't be a problem.

TimmyAeberli commented 2 years ago

Great call. Both services offer Isochrones (definition), which would allow us to shift from Radius=[Distance] to CommuntingLimit=[Time]. However, I found no way to have a public transport dependent Isochrone (include communting time by train). Isochrones in both services are calculated for automotive transportation.

I did find a app ÖVExplorer that allows to do just that: image

ACTUAL PROPOSED SOLUTION: I then searched for a API that has a Isochrone ZIP Code filter and found this with (Traveltime), I got an API-key they offer 1000 requests per month. And Switzerland is a supported country, so I checked the approximate accuracy: It seems to be fairly accurate. However, we only get longitude & latitude in the response and would then have to calculate the ZIP codes within that shape like this. @stefanleminh do you think that is feasible?

alternatively, we could use maybe (Mapnificent), (also on github)

We could also use it in a later stage for display in maps, when browsing the appartments listed. Additionally it is worth noting, that we can use https://developer.post.ch/en/address-web-services-rest for address-verification (at a later stage).

stefanleminh commented 2 years ago

I think we should go with the solution that is the easiest to implement - The distance doesn't have to be exact. I think it doesn't even matter too much whether it's direct distance or by public transport. You usually just want to know if it's within the general area of the radius and public transport can change for people.

TimmyAeberli commented 2 years ago

I contacted https://ezcmd.com/world-postal-codes (first comment and screenshot) for a free API-key for non-commercial use. However, until then we might work with the 190 calls per month. It should be sufficient for our use. And if we get to that limit, at that point it might be worth paying 9$ a month, since it indicates that Marketplace is widely used by AKROS employees.

stefanleminh commented 2 years ago

Looking at OpenRouteService, maybe a solution could be:

  1. Convert the given ZIP code from the search into coordinates with the Geocode API

  2. Convert the adresses of each result into coordinates with the Geocode API

    • I wonder if we should do do the conversion when we create ads and save the coordinates in the DB so we wouldn't have to make requests to the API for each search request - Then again the API has up to 2000 daily requests so we should be fine. We will save the coordinates in the database.
  3. Calculate the distance between the ZIP-Code from 1 with each result with the Directions API

  4. Filter out any result that is not within the distance given from the search.

TimmyAeberli commented 2 years ago

we'll run with Stefans Solution! Story is ready for refinement.