How to get the directions north/south/east/west with google maps api?
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? Thank you.
Upd:Here is what I get:
m.position.lng() - c.position.lng() m.position.lat() - c.position.lat()
Let me give the idea.
You can use
slope. Assume you have a marker
M1 and center marker
Slope should be equal to
(C.lat - C.lng)/(M1.lat - M1.lng)
If the slope happens to be nearly 0 it can be either East or West if
M1.lng > C.lng it should be West.
if slope is nearly 1 it is either South West or North East. Then, if
M1.lng > C.lng it is South West
If slope is nearly -1 it is either North West or South East. Then i
M1.lng > C.lng, it is North West.
You can use the same approach for other directions