Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nearest bus - direction / heading #6

Open
Elixeus opened this issue Mar 23, 2019 · 2 comments
Open

nearest bus - direction / heading #6

Elixeus opened this issue Mar 23, 2019 · 2 comments

Comments

@Elixeus
Copy link
Collaborator

Elixeus commented Mar 23, 2019

when querying for nearest bus - we want to return the direction of the bus as well as buses that are coming to this stop and not output buses that have already passed this stop

@vr00n vr00n changed the title nearest bus near me nearest bus near me - direction Mar 24, 2019
@vr00n
Copy link
Member

vr00n commented Mar 24, 2019

Options:
make sure you return buses that have not already crossed this position.

So select st_near(my_location) from device table where device's previous "n" locations were > (distance from this and next bus stop)

or compute a heading from the device table
https://stackoverflow.com/questions/3932502/calculate-angle-between-two-latitude-longitude-points

@vr00n vr00n changed the title nearest bus near me - direction nearest bus - direction / heading Mar 30, 2019
@vr00n
Copy link
Member

vr00n commented Apr 14, 2019

Option1 : Use Math

def angleFromCoordinate(lat1, long1, lat2, long2):
    dLon = (long2 - long1)

    y = math.sin(dLon) * math.cos(lat2)
    x = math.cos(lat1) * math.sin(lat2) - math.sin(lat1) * math.cos(lat2) * math.cos(dLon)

    brng = math.atan2(y, x)

    brng = math.degrees(brng)
    brng = (brng + 360) % 360
    brng = 360 - brng # count degrees clockwise - remove to make counter-clockwise

    return brng

Option 2 : Use google computeHeading (not a service though)

You just can use the google maps computeHeading:

var point1 = new google.maps.LatLng(lat1, lng1);
var point2 = new google.maps.LatLng(lat2, lng2);
var heading = google.maps.geometry.spherical.computeHeading(point1,point2);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants