LBS – How to find User’s Home and Work location

LBS (location based services) for mobiles can be improved by knowing user’s work and home location, for eg. you don’t want to disturb the user with a push notification while he is busy working. There can be many uses around knowing this sensitive data. As for android devices google is able to predict the same and providing you with alerts at the right time. Mobile OS doesn’t track this information in general and hence doesn’t have an API for the app to access this information.

So, the only way for the app to know about user’s location is by detecting the location at various intervals of time. Hypothetically lets say the app get’s the user location every hour, but the challenge is how do you find home and work location using this location data.

Method 1

Not considering extreme cases, we know that a typical user would definitely be in office from 10.00 AM to 5.00 PM, so during these period the app receives 6 locations according to the assumptions made above. It’s hard to find which of these 6 locations is the exact work location, so geometric centre would be right solution, but what if the user has gone out for lunch during the work for a couple of hours, then the geometric centre will give us the wrong work location. Right method would be to cluster the locations based on the maximum distance between 2 locations and pick the cluster with maximum locations to find the geometric center which would be the user’s work location.

I think estimating work location for 1 day will not be enough, you have to observe the user over a period of time to get the exact work location. 10 days is a good period to get a right estimate, which would mean we have to track the user’s location for 14 days(5 working days per week). Each day we get a rough estimate of user’s work location and by clustering these day locations obtained based on the maximum distance between 2 locations and picking the cluster with maximum locations to find the geometric center will give us the exact work location.

The app needs to keep track of the user’s last 14 days locations and calculate the work location with the data over past 2 weeks to keep the data accurate and fresh, this way if user starts working at new location, we can get the new work location in 7 days.

Finding home location uses the same algorithm except that the locations used would be from 11.00PM to 6.00AM, as user stays at home during midnight and the 14 days period handles the variations.


In this method, make clusters of the 24 locations based on the distance between locations. Pull out the top 2 clusters with maximum locations and identify the time periods. One of them must be work location and other is home location. Do the same over a period of 2 weeks to get a proper estimate of user’s home and work location. But to find which of these locations is home location, observe the locations over the weekend assuming user doesn’t go to work on these days :P.

Happy Coding…