I want to calculate the estimated location. Suppose i have source (A) and destination (B). Let say vehicle take 18 hours to reach from source to destination. After one hour it departs, the vehicle is at point C. At point C i have speed, Lat Long and distance cover from source (A). let say it cover 100km in 2 hours at point C. At this point i want to calculate the estimated location i.e where the vehicle will be after 2 hours or what will be the location after 300 km from point C with respect to current time,speed ,location and distance at point C. Vehicle is moving along the road. Please help me in this regard. Thanks
Not actual code but some possible hints to the answer. That's how I would do it.
I assume that you use the Google Direction API and that you know how to calculate a distance between two points from their coordinates.
From this, my idea would be call the API to get your route and to the use the polyline part of the answer. The polyline is encoded with this algorithm. You can use this javascript code to get your list of points.
You then calculate the distance between each per pair of points from the start. When you reach the distance from point A to point C, you know on which segment of the polyline your vehicle should be. To get the exact coordinates on the segment, I suggest you use the interpolate function of the Google Maps Geometry API.
Of course, if your route contains many segments, you might want to use a heuristic such as approximating the search of the middle segment by filtering your list by using a box of coordinates.
Related
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
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.
I got a set of wgs84 coordinates to place a polygon on Google Maps. I am wondering if i can use the same coordinates to get a compass direction of the coordinates. I don't need a solution specific for Google Maps, javascript or php. I am just wondering what the right approche would be.
Something like this would be the end result. I understand it needs some sort of algorithm in the background
I found Geolib and the 'getCompassDirection' function but this function only allows 2 points to create a line and get the bearing(angle) of that line.
You can't get any direction information out of a single position coordinate.
Position coordinates don't represent any knowledge about the orientation of an object. Therefore you need something that has direction (i.e. a vector between two coordinates) to calculate compass direction. That's exactly why the function you mentioned asks for two points.
This means you can get a compass direction for any edge of a polygon (by using its two end points), but not for its vertices.
Hope this helps!
I need your help. I have a database table called 'journeys' which contains (fromlat, fromlng, tolat, tolng) and I also have another table called 'cityPostcodes' which contains (postcode, lat, lng).
Users can search journeys by just entering 'from postcode' and 'to postcode'. After mapping these postcodes to their actual physical locations, I want to calculate likely journey matches based upon these postcodes.
What I am struggling is, how to check if two journeys are heading to the same direction? for example, the journey searched by the user and those in the 'journeys' table.
You could use something like the geospatial extension for PHP to calculate the cardinal direction of the from/to lat/long coordinates to see if they head in the same cardinal direction.
You would need an origin latitude/longitude set of coordinates and a destination lat/long for each journey. You can then using something like the Haversine formula or Vincenty's formulae to calculate distince and derive the cardinal North/South/East/West direction of the line segments along the ellipsoid.
I'm trying to do some experiment with an app. I want that, given my location and given a distance, I get a point in Google Map to which I could walk that distance.
That has some complications since getting a point X miles out from you is "easy" but it's unlikely you'll actually walk that amount of miles unless you can actually go in a straight line.
The approach I followed is using google.maps.places.PlacesService and the function nearbySearch given a radius. Then I process the distance to each returned point and luckily I get one point I could walk that distance far.
However, I've been trying some edge cases, like picking a road near a desert and then it won't work cause "places" are points of interest and that may be only just a plain road with nothing else than boring bushes for a long, long way.
In my mind it just should follow that road for the given distance and then stop.
To be clear:
I want to know from my starting point, which would be my ending point if I were to walk 1 Km
Do you have any better approach to this kind of situations?
The google.maps.DirectionsService class will calculate the route a traveller would take, given an origin and a destination. It accepts a google.maps.DirectionsRequest object. The DirectionsRequest has an option called TravelMode, which will accept any of four constants (BICYCLING, DRIVING, TRANSIT, WALKING) from the google.maps.TravelMode class.
To find a point, say, 3 kilometers from your location, I would:
Request walking directions from DirectionsService, using your current location and a point approximately 3 kilometers away from you.
Iterate over the overview_path, continually adding the length of the current segment to your grand total.
Cut the last segment to length when you exceed 3 kilometers, creating a length whose final length is very close to 3 kilometers.
I made you a Plunk demonstrating how this could be done.