This is a little API project which takes a given IP address or it takes the client IP address along with a given city name and country iso2 code and it calcs the straight line distance between both points.
http://your.domain.com/api/v1/get-distance?country=pa&city=Panama City&ip=153.134.188.49
It is MIT license so feel free to use it in your own projects.