Can Vehicle Tracking be done without using Google Maps API? - javascript

My web application is intended to track a college shuttle on a predefined fixed route. There are certain pickup points on the route which are fixed. Through the web-app, the user should be able to get the estimated time of arrival of a college shuttle. For that, I would require the actual distance - along the route and the speed of the vehicle. The haversine formula for the shortest distance would not apply over here.
However, My friend thought of a solution that is to plot points along the route at a fixed distance say 20 meters, and calculate the distance in relation to the points. For example-If Shuttle is at point 5 and the user is at point 10, then the distance between both of them would be computed as (10-5)*20 i.e 100 meters. This solution isn't highly accurate but it would work.
How would I determine the shuttle location with respect to the points? I have the live coordinates of the shuttle, the coordinates of all the points on the route. What is the best way to get the result such as
Shuttle location is point 5. I am using Javascript and NodeJS. For Database MongoDB. Current location is obtained using Geolocation API

Leaflet is a great platform for maps and there is a plugin for k-next-nearest-neighbor searches here https://github.com/mapbox/leaflet-knn
The nearest stop along the route to the bus would then give you what you need I think

Related

Leaflet Drawing a trail based on markers previous path

I want to try and draw a trail that follows each marker I have that is updated live from a MySQL database table with GeoJson every 8 seconds.
I have tried drawing a polyline from the Start Position to Current Position of each of the GeoJson features/leaflet markers but that won't work of course since it only takes into account the start and current position and not any turns of direction changes made underway.
I am trying to make something that draws a direct trail behind each of the markers based on the previous positions. My GPS trackers submit latitude and longitude to a database table every minute or so. My idea is that I could maybe create a new table and just make it submit every latitude and longitude from all GPS trackers and draw LineStrings for each marker based on that maybe?
But I think that wouldn't really be a good efficient way to do it since I would have multiple GPS trackers submitting latitude and longitude every minute and the GPS trackers would be moving very slow so it is very minor changes each time (if even any at all since the slow moment speed and only 4 decimal precision in the latitude and longitude there could even be cases without any changes in the submitted data)
Does anybody here have an idea for an efficient way to draw a live updating trail behind each marker from GeoJson? :)
Think of the database tables as "persistent storage" for all the data.
Have your client, when it receives more info (every 8 seconds and/or every minute) do the following:
SELECT the last location from the``Current` table, which has 1 row per item being tracked.
Draw on the canvas (or wherever) the line from where it was (step 1) to where it now is (incoming data).
INSERT the new location into the History table.
UPDATE the current location in a table that has just the Current locations of all your vehicles (or polar bears or dolphins or snails).
Four decimal places won't work for snails. It has a resolution of about 16 meters or 52 feet. See Representation choices . Four may not be sufficient for vehicles; some of the time it will erroneously show the vehicle in a ditch or on the wrong side of a highway -- simply because 4 decimal places is not enough.
I don't know about GeoJson; I'm looking at what can be done with MySQL and HTML5's "Canvas".
On a slow machine 100 changes per second should be possible. So, if you don't have a thousand things moving around, I don't see a performance problem.
The push-me, pull-me Problem
Since a web page is stateless and the data is flowing the wrong direction, it will be difficult to design a setup where the path is continually showing on the screen, and being updated periodically (every 8 seconds).
One approach is to 'push' the data into the database (as discussed above). Then have the web page that is showing the trail poll the database to see if there is something need to display.
Such "polling" would be done via AJAX that is called every, say, second. The reply would include all new location changes. The web page would paint new line segments based on whatever data was returned (zero or more kangaroos, as appropriate).

Find closest city via GPS coordinates - algorithm

I am given coordinates for my location (55.1858, -162.7211). I would like to find the city I am at (or near) if it exists in my dataset. The dataset (tens of thousands of coordinates) has all cities that I am interested in, and one or more coordinates corresponding to that city (depending on the size of the city):
Cold Bay, Alaska, 55.1858,-162.7211
False Pass, Alaska,54.8542,-163.4113
King Cove, Alaska, 55.0628,-162.3056
...
What's the best algorithm (preferably in JavaScript) to find the city that I am in (Without using any APIs, Google Maps etc..)?
I had a few ideas, but they're probably not the best as they're all brute force methods:
Draw a radius around my coordinates of a certain distance and then loop through the dataset to find if any of the existing coordinates are in this radius. If one or more are, then loops through them and see which I am closest to via their distance.
Somehow, start to round my coordinates at the furthest decimal place and check after each rounding if this new set of rounded coordinates exists in the dataset.
I feel like these are really bad ideas and would love some guidance or recommendations on good algorithms for this type of searching.

Google Directions API - Route to a wider area

I think it might be impossible, but I wanted to check with you guys.
The Google Directions API. Is it possible to calculate the route to a larger area, rather than pin-pointing to a Lat and Long?
E.g. Imagine a huge national park.. there are many ways to get there, and many 'entrances'. Is there a way to force Google Directions API to calculate the quickest route to a 'general area' or a custom polygon?
Not sure what you expect, but usually large places as you described, have a kind of center point that will be used by the API when requesting directions based on its place name.
Depending on the travel mode (walking, driving, etc.) you will see that the directions don't always end at the same exact coordinates. This is particularly true for places like National Parks, etc.
There is no way (yet) to get a place boundaries via the API. This is a long awaited (10 years...) feature request to which you can of course subscribe.
If you can define the area by yourself (as a Polygon for example), you could then take a few points on that shape's borders (ie. North, East, South, West) and use the Distance Matrix API to find out which point is the closest/shortest from your origin location (obviously you could also just save some points around your place instead of a Polygon).
If you need these points to be on a road, (if you need DRIVING directions / if you want to increase your chances to be able to retrieve directions), you could first use the Google Maps Roads API and do a Nearest Road request for each of the defined "entrance" points and use the returned coordinates for your Distance Matrix requests.
Once you find out which of these points is the closest from your origin location, you can request directions to it using the Directions Service and display it on your map.

Handling large amounts of markers on google maps api v3

Question is based on experience with googlemap api V3 otherwise please ignore the question
Summary of the question:
question consits of a lot of information (background information about use case), but the question have only
2 clear and specific parts
part one is about clustering markers
an its using in this case
part two is about loading new markers
(respective loading new groups of markers) when you move with view
port
both parts are still about same thing about handling with the points (markers) in the viewport, when you solve one you have to think on second part and otherwise
Info about the usecase and desribing of the question
Imagine application of hundreads or thousands points (places) defined by latitude and longitude which are stored in database. I will show the places on the maps. Map will be divided this way:
the map will be divided to regions = center of the map will be set to some specific latitude and longtitude from that region region (for example the main city of the region) - for simplicity it will be 2 known coordinates
the number of regions is < 20
in each region will be some routes, each route will consists of some points (like you have road map and go from one city to another city and there are some towns on the way for example town1, town2, town3 => so you have 5 points - only the points are important)
region consits of < 100 routes, each route consists of < 100 points (=places/=towns) (by point understand latitude and longitude coordinates)
so I mentioned 3 types of dividing my area: regions > routes > paces in route; this are dividing what you will be able reach from menu of my web application (=php+html5+css+js)
next thin what is important are the places - number of places would be in thousands and sence of all of it is that you choose some starting point and wanna show the nearest places ( for example region1 -> route 2 -> city 4 on route 2 its on latitude x and longitude y and i wanna show only relevant place in viewport = places around the city 4 on route 2)
There are some problems which comes up: (the bold are important for me)
storing the places in db (MySQL) maybe not best idea, I'will consider
some sorting places by coordinates to some groups for easier requests
to db
too many places in viewport (for exmple city 4 on route 2 is center of the map and there are 50 or 150 places aroud it) - I found
some soulution as clustering the places - question part 1 is if
somebody have experience with that and if its enought for running it
on normal computer or mobile browser (don't wanna kill the app by
tunes of markers on the viewport) - what I read this can group the
markers together and show more specific if you zoom in
problem 2 is moving from one region to another (or just moving from the place) - example you have center point of the map called A
(=city 4 on roadmap 2) and in the view port there are loade only
points which fits to this view port, then you move with the map to
the right and you should load new point cause your viewport is
changed = question part 2 is what could be good practise for loading
that points - if you turn "10 pixels" to the right call the db for new places, then you turn "another 10 pixels to the right" again call db for another new places is stupidity, cause I would kill app only by requests for db, sorting, etc.
You can use a bounding box to filter most of your places. Then use the harvesine formula.

How does Google Maps and Nokia Maps generate routes from point to point

I will like to know if anyone has an idea on the concept behind point to point route generation on google maps and nokia maps. What logic was used to determine the route and generate directions from any point on the map to another? I wouldn't mind guesses or something of that sort. I just want to understand, how it works.
This is just a guess, but probably something like Dijkstra's algorithm. It most likely is some kind of graph-search algorithm, with each node representing an intersection and each edge representing a section of street.
I will also add that the graph here is likely also weighted, with each weight corresponding to how important the road is. For example, Interstate highways may have a greater weight than state highways, which have a greater weight than local roads, which have a greater weight than simple streets. Optionally, toll roads may have a lower weight than non-toll roads.

Categories

Resources