Hacker News new | ask | show | jobs
by dmcginty 1802 days ago
I was in a job interview several years ago and I was given the following prompt: "You have a database containing locations with their corresponding latitudes and longitudes. We want to be able to input an arbitrary latitude and longitude and have the program return all locations within a radius from that point from the database." My initial reaction was to say "I would use a GIS library/API", but the interviewer wanted me to come up with the algorithm on my own. I had done some GIS work at a previous job, so I started explaining how I'd approach it. I was a bit rusty, but I started explaining what I could remember about the Haversine formula and rhumb lines. The interviewer told me that I was overcomplicating it and explained that I can treat the latitude and longitude as standard Cartesian coordinates. I explained how that wouldn't work as they're spherical coordinates, not planar, and lines of longitude aren't parallel. I believe this is where the problem went from being an issue with technical approach to an issue with expectations. What they really wanted was an algorithm that could find all points a given radius from an arbitrary X,Y coordinate. However, by trying to turn it into a real-world problem with latitudes and longitudes they neglected to consider that they had fundamentally changed the challenge. I'm quite stubborn, and I tried to point out that the question was much more difficult than they intended, but they were equally stubborn and insisted that spherical coordinates could be directly converted to planar coordinates with no issue. Long story short, I didn't get a call back and I'm still frustrated about that interview ~3 years later, but I'm also glad that I stood my ground rather than give an incorrect answer.
4 comments

There's a sizable portion of people believing that spherical coordinates can be directly converted to planar coordinates :-).
Mathematically speaking, isn't it true you can compute the coordinate transformation (with your choice of map projection, perhaps ignoring the poles)? The real problem is that your metric / notion of distance has changed, so you can't simply compute distance as sqrt((x2-x1)^2 + (y2-y1)^2) and expect it to map neatly to a circle on the globe.
I would have just as stubborn about the spherical-to-planar issue. IMO it's easy to illustrate by pointing out an extreme example: two longitude lines can be feet apart near the poles (ignoring the intersection aspect for simplicity) and miles apart at the equator. If someone doesn't understand that... I don't know what to say.
Some times "good enough for jazz" applies I solved a similar problem - find all geo locations within 2 hours driving time of x,y

I basically used the great circle distance (using I think a CPAN module) as an approximation - this was for geotargeting AdWords.

Maybe they were expecting converting to 3 dimensional Cartesian coordinates (X/Y/Z), then check that one point is inside the sphere of given radius from the other point?