Javascript – GPS location tracking in laravel

google-maps-api-3, gps, javascript, laravel

I am currently working on a University project and I am going to create a hitch hiking mobile app. I am looking to use phonegap and Javascript on the front end and laravel as my RESTFUL API. I have looked at he Google maps API documentation but I have still not seen a plugin for Laravel which allows GPS route details to be stored on the backend in laravel.
I presume the mapping of routes between drivers and hitch hikers will need to be done on the server as details of all routes (journeys) will need to be stored and for searching.
Has anyone ever worked on a similar hitch hiking project and how would you check if a hitch hicker's route matches with a Driver's route. Surely this mapping must be done on the server and is there any API for Laravel that supports this?

Best Solution

My interpretation to how your service will work is that both hitch hikers and drivers will state their current location and their intended destination, and hitch hikers will be able to request rides based on matching routes/destinations (which is a pretty cool idea actually).

Based on that interpretation, here's how I might go about implementing it.

1. Create a Journey

A Journey model would be a the journey the user wishes to make. It would be comprised of many Waypoint models (at least 2, the minimum being the start and end points).

There would be a one-to-many relationship between a Journey and Waypoint.

A user creates a Journey and you use the Google Maps Directions API to store the Waypoints for it.

2. Periodically update a user's location

A user will eventually move between waypoints. When they do, you want to know where they are so you can update their position so that they're able to be accurately represented on a map of active users (I imagine you'll have one, displaying the locations of various Drivers and Hitchhikers, similar to Uber).

3. Match users based on similar waypoints

Use the waypoint data you have stored against a driver and hitchhiker's routes to find similar routes/journeys and make suggestions as to which hitchhikers a driver may pick up. You can even use the API data to give estimated times of pickup based on the distance between the driver and the hitchhiker.

There's more to consider, but that'd be a pretty decent starting point.

You would want to think about re-routing (what if a user can't go between certain waypoints due to roadworks, or perhaps they take a wrong turn - think about how your SatNav might handle it), perhaps the ability to plan trips in advance, etc.

To actually answer your questions, yes, if you wanted to use Laravel for this you'd map the routes and match the waypoints server-side.

Let's take the scenario where I am a hitchhiker.

  • I want to get from A to G.
  • I'm currently at waypoint C
  • Driver X is on another route which happens to have my waypoints C, D, and E in it. To find Driver X, you could do something like (pseudocode):

    // Find a driver with similar waypointsDriver::withSimilarWaypoints($myJourney->remainingWaypoints())->all();// withSimilarWaypoints scopefunction scopeWithSimilarWaypoints($waypointsCollection){    $query->whereHas('waypoints', function ($query) use ($waypointsCollection) {        $query->where('passed', 0)->whereIn('waypoint_identifier', $waypointsCollection->pluck('waypoint_identifier'));    }}

In this case waypoint_identifier would have to be the same for me and Driver X, so perhaps a hash of the waypoint object or you could use place_id as returned by the API.

You'd also want to make sure you're not matching against waypoints you've both already passed (hence remainingWaypoints() and where('passed', 0).

  • Driver X is estimated to arrive at waypoint C in 8 minutes, so I decide to wait for them (or I can request a lift via the app)

All that should be a pretty decent jumping off point for your service. I quite like the idea – good luck!