3

I'm working on a site for at-home services. What is the best practice to define a service provider's service area?

My initial thought was to define each provider’s service area as a set of zip codes. If the customer requests a service, simply search for providers with matching zip codes - easy enough. I’ve done a bit of research and I’m confident it will work - provided I can find an accurate zip code database. The best database I’ve found is costly, and before I embark on this zip code endeavor, I want to make sure there isn’t a better way to accomplish this task.

For example 'Google Business Listings' used to ask you to define your “Service Area”. How did Google store this data – as a lat/lon coordinate box or circle?

It seems this process for defining and storing a “service area” and then matching it to a request would be commonplace – so what are today’s best practices for this process?

  • 1
    Zipcodes are pretty easy but they can vary wildly in geographic size. The can also cross political boundaries such as city/county borders. – JimmyJames Nov 1 '17 at 15:48
  • Not to mention not all addresses have zip codes. The Zip Code is an American concept, some countries have a Postal Code (like Canada), but several countries do not. For example, the equivalent information in Japanese addresses is encoded into what we would consider the house number. Do you need to service an international audience? – Berin Loritsch Nov 1 '17 at 16:29
  • 1
    And/or be gerrymandered. This has lead to some fun calls with food delivery places: "Sorry, you're not in our delivery area" "But you're across the street...." "Sorry dude, not in our assigned list of zipcodes". – Clockwork-Muse Nov 1 '17 at 16:32
  • @BerinLoritsch - Japan does use postal codes?. The ordering is reversed when written in Japanese, so things are written mostly least-specific->most-specific, and the postal code comes first. – Clockwork-Muse Nov 1 '17 at 16:36
  • @Clockwork-Muse, Right. Naïve address implementations would not be able to distinguish between a house number and the postal code. I will say the postal code system in Japan is more regular and evenly distributed--at least in Tokyo and Osaka. Here in the USA I get my mail from a post office that is further away than the people in the townhouses next to my development. – Berin Loritsch Nov 1 '17 at 17:18
4

You need to define what your service providers mean by service area. There are several ways to do so, depending on how specific you want to get.

Here are some options ranging from simple to more difficult:

  • Lat/Lon of the service center and a radius. I.e. 20 miles from 34.1234, -81.2235. This is by definition a ellipse (latitude and longitude don't increment in the same proportion on the ground)
  • A geographic polygon specifying the region (like Zillow lets you do).
  • Imprecise mapping of adjacent postal code(s) to a geographic polygon, requires a database to perform that mapping

So you really need to think about the service area from the perspective of how the service provider defines it. If your service provider is willing to travel X number of miles, then the first option might be good enough. If your service provider has a specific area in mind, they might want to draw the area on a map and let that be their service area. If your service provider says they service postal codes X, Y, and Z, then you might have to generate the bounding polygon from those zip codes.

The simple radius query is fairly trivial to do in databases that have geospatial support. All other options will require a polygon stored in the database. To optimize that query, exclude all records that don't have an intersecting bounding box first. Geo-spatial polygons are slow to perform, so a quick pre-check on the bounding box usually speeds the performance of the query much more quickly.

The majority of the cases can be easily implemented with the first option, but you may find yourself subject to some edge cases where the road to get to a location will go outside the range.

1

How to do this 'best' is something that really depends on how you define 'best'.

Zip Codes are probably best for simplicity of storage and lookup, but will be sub-optimal for lacking the ability to account for actual distance from service origin (e.g. the provider's office) and boundaries of authority (e.g. state boundaries if your provider has a license to work in a given state) and blackout areas (e.g. if there's a specific street or neighborhood your provider refuses to work in for one reason or another).

So short term you could probably start with zips, but plan to grow into a database that will support geospatial queries, so that you can later add in more detailed service area options.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.