![]() ![]() In the formula above the constant 6380 is the earth radius which is the main factor for the precision (because the earth is not a even ball), so play with that parameter at first, before you use a more complex algorithm like the Vincenty's formulae. You will never need such a precision for this task, where you have to use the altitude or so. But this function should be enough for the moment, especially under the view of performance. There are many other approaches to get the distance between two points. Let's go to the implementation of such a function in MySQL - we call it distance(), which will return the number of kilometers between two points: CREATE FUNCTION distance(a POINT, b POINT) RETURNS double So we have our first optimization step, that we only check all entities against our fixed point on the map instead of really search in a circle. So what do we need? Think about a simple method to draw a circle or even better to get the distance between two points on the map. The main idea behind all of this is that you span a circle around a point on the map and search for all entities that will fall into that area. We could also say, finding locations near locations. ![]() ![]() For now we will concern on finding people near me under a territorial view. I will treat these social mappings in later articles. There are many nice things to work on, like finding the friend path to someone (to follow the theory, that everyone knows everyone on the earth over at most 6 edges), show friends of friends and the little more complex task of friend suggestion through a social graph. The most common problem on developing a social network is, that you have to reflect a real world into the computer or more specific into the database. People near you with MySQL December 27th, 2009. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |