0

I have a simple Android app that keeps track of users' location, using the following setting of the LocationManager to avoid constant updates and thus battery drain

  • minTime = 60sec (minimum time interval between location updates)
  • minDistance = 50m (minimum distance between location updates)

So far so good. However, not unexpectedly, I kind of suffer from the limited accuracies of GPS. Ideally, I would like to identify in which restaurant a user is eating, even if the restaurant is in a shopping mall with other restaurants or other POIs (e.g., shops) nearby. Right now the accuracy is not good enough to make this reliably work.

I wonder if this a common problem and there are tried and tested solutions.

My current approach is to keep a history of a user's last locations. Every time the user is moving - I use the ActivityRecognitionApi for that - I clear the history. As soon as a user is still, I add any new location to the history. To identify a user's location, I simply average the coordinates - using a simple mean (maybe better the median); I'm not far from the equator, it's only for quick testing. The assumption here is, of course, that all coordinates in the current history are indeed coming from the user being still at one location. Another approach might be clustering. With this I wouldn't need the activity recognition, which is also never 100% accurate. But if there is simpler solution out there, I'd be more happy.

The whole thing is just a basic research prototype. So the backend component handling user's history is in Python. Maybe there are good packages out there that can help me here.

1

I've followed FelixIP's suggestion to use Convex Hull Peeling. Since the example in the linked post is written in R, I post here the corresponding method in Python. It's extremely simple since the heavy load is done by scipy.spatial.ConvexHull.

import numpy as np
from scipy.spatial import ConvexHull

def get_poi_by_convex_hull_peeling(coord_list):
    coord_list = np.array(coord_list) # Just in case it is not a numpy array
    while True:
        try:
            hull = ConvexHull(coord_list) # Will throw an exception if len(coord_list) < 3
        except:
            return np.mean(coord_list, axis=0)
        if len(hull.vertices) < len(coord_list):
            coord_list = np.delete(coord_list, hull.vertices, 0)
        else:
            return np.mean(coord_list, axis=0)

points = np.random.rand(30, 2)   # 30 random points in 2-D
print get_poi_by_convex_hull_peeling(points)

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.