# Get distance in meters between lat/lng coordinates, divided in North and East direction

I've got 2 couples of lat/lng coordinates and I would like to get distance between them in meters, but divided in X (east) and Y (north) directions.

I've found this function in a Stack Overflow answer to get distance between 2 points, but I don't know how to separate the North and the East distance:

``````var rad = function(x) {
return x * Math.PI / 180;
};

var getDistance = function(p1, p2) {
var R = 6378137; // Earth’s mean radius in meter
var dLat = rad(p2.lat() - p1.lat());
var dLong = rad(p2.lng() - p1.lng());
var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.sin(dLong / 2) * Math.sin(dLong / 2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
var d = R * c;
return d; // returns the distance in meter
};
``````

I've found the solution. Here is a javascript function to get the distance divided in east and nord gap:

``````var getDistance = function(p1, p2) {
var R = 6371e3; // metres