How to dynamically assign a caller ID to be closer to the person you call
There are cases when an organization or company has large number of offices and associated phone numbers across several states. They may also have customers, or people they call often also in various states. However, it is frequent habit for a person to not pick up the phone when the caller ID is unknown to them, especially if it comes from another state or another dial code area. In opposite, if the caller ID is from the same state or area code, it gets a higher chance of being picked up, since that could be a call from their kids calling from friends phone etc etc...
The solution, of course, would be to assign caller ID from the same dial code as the called persons number. However, the number of NANPA codes (code areas) exceeds 400 already at the moment, and the list is growing. So the most sensible solution would be to assign a caller ID from the area code most closer to the called number.
Therefore the idea is, to give each NANPA area code a geographic location, a latitude and longitude, and to measure a straight line distance between these points. While in theory, the points can be allocated imaginary coordinates, not connected to real world, it would probably be easier and more human-readable if points corresponded real locations. We took that approach and planted each of the codes on the map as close as possible to the regions they serve. So. for example code 305 landed in Miami, FL, code 813 - somewhere east of Tampa, and 321- south east of Orlando. It took some time to place all of the currently existing 370+ US and Canada codes, but the result looks good:
Besides that, by visualizing the code locations, it also give a possibility to customize the setup, by moving the pointers over the map. That might be useful in cases in somebody feels that some neighboring area codes should come closer to each other in order to receive calls with that caller ID, or exactly opposite: to prevent caller ID from neighboring areas. By moving points around one can get best possible arrangement of caller IDs, in the same time keeping an eye on the whole picture.
For example, we need to call a person in area code 239 in Western Florida and we have 2 caller ID numbers close by in Miami area: one in 305 and other is 786. if we look at the precreated map, we can see that orange line from 786 is shorter than green one from 305. The system will pick 786 as the first choice, and display as the caller ID:
Now, if for some reason you would like that users in 786 area are presented with Miami code 305 instead, just move the pointer, save and you have new arrangement. Now the green line to 305 is shorter than the orange one from 876, and caller ID 305 will be displayed.
Now, when the points are arranged, the maths of getting shortest distance comes in play. One approach would be to use geospatial data storage, and work from there. However, we wanted the solution as simple as possible, so it could serve very large amount of calls, and be cached, if necessary. So instead we opted for simple decimal numbers for latitude and longitude storage, and assuming that for our purpose earth is flat. That gives us nice option to use Pythagorean theorem to calculate distance between two points. to make it even faster, we do not even need to know exact distance, we just need to know which of the neighboring points are closest. Therefore a simplified method: just get the sum of the squares of the corresponding latitude and longitude differences between our point and neighboring points and sort them in ascending order. That search will return a list of points arranged by distance. Now the first caller ID which matches the list, can be assigned to the caller.
That solves the problem of closest caller ID if you have many, and increases your ASR of the calls.