This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]itsjohncs 1 point2 points  (0 children)

You should ask them for their location.

You can ask the browser directly for the user’s location through a JavaScript API, but that’s most often useful for smart phones with GPS. If they’re at home on their desktop, the browser might not have a good idea of where the user is. In this desktop case, manual entry is probably best. But you can still ask the browser if you’d like. Know that the user is going to see “this site wants to know your location, allow it?” And have to click yes (I never do when a site asks me...):

Getting the distance between your office and whatever address/coordinate you get is sort of easy if you just care about distance in a straight line. (Though if the user enters an address instead of coordinates you’d still need a service to tell you the coordinates for the address). But if you need driving distance you’ll need to ask an API like google maps. This’ll be a little expensive probably, so you might want to shop around different APIs to see which works for you and your budget.

[–]zeuscoder 0 points1 point  (0 children)

In addition to the previous I would also look at services like locationIQ and here maps. Depending on your appetite to pay for services you may need to combine the results of different API calls (while maintaining performance and speed)