Advanced sorting question about drupal views
You will need help of views_php module. This module will help to sort views rows with a calculation. You need to go through.

But in your case, The calculation has a value from current page. So you have to get the current page value (lang, lat) in sorting field, may be you can use it as a global variable or call a function from inside the php field.

Hope this helps you. :)