Joe Steinbring

Locating your user in meatspace

Event Logo

Thursday, September 15, 2022 - 6:00 PM UTC, for 1 hour.

ON THAT (Online Only) Open Space


Whether you are building a dealer locator or something to lists pizza joints that deliver to a location, knowing your user’s physical location is very important. I intend to show how to detect where the user is by both what their browser reports and by what their IP address is. I then intend on showing how you can use the US Census Bureau’s Gazetteer Files to build a web service to convert from a zip code to latitude/longitude coordinates and from a city and state to latitude/longitude coordinates. Finally, I intend to show how to use the haversine formula to determine the distance between where the user is and possible points of interest. I am also going to show how you can move a lot of this logic into node scripts on Cloudflare Workers, so you don’t need to clutter up your client-side code. I intend on beginning this talk by diving into how you can use navigator.geolocation to determine where the user is, how you can build a webservice to determine where the user is based upon their public IP address, and how a node script running in Cloudflare workers can make this relatively easy. Next, I intend to go over the possibility that the user might want to use a location that they are not at and how to accomplish that. The United States Census Bureau publishes US Gazetteer Files. These are listings of geographic areas, for selected geographic area types. Using their places dataset and their ZIP code tabulation areas dataset, you can build tables that go from city and state to longitude and latitude and go from ZIP code to longitude and latitude. Once you have that, it is easy enough to create another web service to handle the conversion. Finally, I intend to show what the haversine formula is, how you can use it to calculate the distance between two GPS coordinates, and how once you have that, you can sort your dataset by that numeric distance. The haversine formula does not consider where the roads are between the two locations but since it is just a math formula, it can be run locally on the user’s system and won’t require additional API calls.


You should know some javascript and have worked with APIs.

Take Aways

  • An understanding of how to find users
  • An understanding of how cool CloudFlare Workers can be
  • An understanding of how cool the haversine formula is
favorited by:
Eric Boyd Robert Nicholson