Calculating likely journey matches based upon their physical locations - javascript

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.

Related

Can Vehicle Tracking be done without using Google Maps API?

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

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.

How to do customer Lat-Long place search in radius using google map api?

I have set of previously obtained latitude & longitude using GIS application for various places.
What i have to do is... I want to show these obtained lat-long on map as marker from my current location to certain radius.
Say if my current location is -33.8665433, 151.1956316 and radius 1000 then I want to show all obtained lat-long as marker falling in this range.
This : https://google-developers.appspot.com/maps/documentation/javascript/examples/place-search helps for specific defined place type. I don't have predefined type.
How to solve this?
Thanks in Advance.
The problem with geo-queries on AppEngine is that datastore limits inequality queries to at most one property. I.e. you can not perform an inequality query on both lat and lon , which basically limits the geo-proximity queries.
The solution is to geo-hash your data: break the map into discrete grid and give each quadrant an ID. Then also mark all places with the appropriate quadrant ID.
An example of geo-hash on AppEngine. There is also a java library that performs geo-hashing on AppEngine: https://code.google.com/p/javageomodel/

how to find latlong from distance?

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.

Find cities within given mile radius from address

I'm using CakePHP/mysql to build my app and I'm trying to get a list of cities within a given mile radius around an address both supplied by the user. So far I have a list of all US cities in a database with the long/lat. I also am using a CakePHP plugin to get the long/lat of all addresses inserted into the database.
Now how do I do the last part? I'm new to the google maps api but it looks like there is a limit on how many queries I make a day. The only way I can think to do it is to check the distance from the address and compare it to every city in the database and if it is within the given radius then they are selected. It seems like this would be way too database intensive and I would pass my query quotas in one go.
Any ideas?
It sounds like you're trying to determine if a given point (city) is within a circle centered on a specific lat/lon. Here's a similar question.
Run a loop over each city and see if it satisfies the following condition:
if ( (x-center_x)2 + (y-center_y)2 <= radius2 )
If this is too slow, you could turn it into a lookup based on rounding the lat/lon. The more values you precompute, the closer to exact you can get.

Categories

Resources