# Getting directions north/south/east/west with Google Maps API? [closed]

for example I have 5 markers and I want to get the direction (E,W,NE etc) for each one of them according to the main one(red in the center). Here is a pic.

Is there a way to do this with google.maps.DirectionsService or calculate it somehow?

• Seems like you can calculate it pretty easily yourself, assuming the points are fairly close to each other. Just do difference (subtraction) in latitude and difference in longitude, and from the magnitude and relative scale of the differences, you can approximate the direction. What have you already tried? Jul 11, 2017 at 9:40
• @BradHards I am using this for now m.position.lng() - c.position.lng() m.position.lat() - c.position.lat() Where c is center and m is marker. But maybe there is some other magic formula to calculate it more accurately. As with this i can only get NE, WS, SE, NE 90 degree sector
– SERG
Jul 11, 2017 at 13:16
• @BradHards And I want to get North or only West direction if the marker is close to the W or N line
– SERG
Jul 11, 2017 at 13:22
• Just do relative magnitude. If the lat difference is more than 2.5 (or 2 or 3, whatever "close" means to you) times the lng difference, you're pretty close to N/S (whichever it is from the sign of the latitude difference ). If the lng difference is more than 2.5 times the lat difference, you're pretty close to W/E (again by sign of the longitude). Jul 11, 2017 at 20:53