# Calculate distance

Hey guys,
I’m having an issue with my Meteor Cordova app.
I need to calculate the distance between two points. First, I decided to use andrei:google-distance, but he did not want to work on mobile.
Then I had sent a request to Google distances matrix services from the server (for the client CORS error), but the phone does not want to call a method on the server.
My actions:
\$ meteor run ios-device
After that I run app from Xcode

Why don’t you simply implement that code on your own? It’s not that hard.

Yeah, if you just want the distance “as the crow flies”, rather than the distance by road, you can just put in a simple function.
Here’s the one I use, it’s in JS rather than C#, and it works with Googles LatLng objects.

``````measure = function(loc1, loc2){  // generally used geo measurement function
var R = 6378.137; // Radius of earth in KM
var dLat = (loc2.lat - loc1.lat) * Math.PI / 180;
var dLon = (loc2.lng - loc1.lng) * Math.PI / 180;
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(loc1.lat * Math.PI / 180) * Math.cos(loc2.lat * Math.PI / 180) *
Math.sin(dLon/2) * Math.sin(dLon/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c;
return Math.round(d * 1000); // meters
};
``````