I am working on an application where I have some roads in a static vairable (say 7 road names with their address and geolocation). The user of my application would have GPS enabled device so I can retrieve coordinates as where they are standing.
I have user location in longitude and latitude and also 7 addresses in longitude and latitude. I want to select 1 of those 7 addresses matching each with current user location and I am not sure how should I compare to select the nearest one.
Say if user is on Armour Road, Peterborough and as the road is quite long, user can be anywhere at that road resulting in different coordinates. So how can I match user coordinates with that it tells me s/he on Armour Road although no matter where at Armour Road.
How can I check if user is on Armour Road or some other targeted road?
You would prob use a circle-distance algorithm to the distance between all coordinates. When you got which one is the nearest you have a really hard problem to solve. If the user is at the road or nearby, if I understood you correctly.
The people at Yelp! solved this problem by acquiring the coordinates of the road. You always have to mind the error in accuracy which brings you to the point of assuming. If you have two possible roads within the same accuracy you are basically always screwed.
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 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.
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.
My requirement is to save the specific are from the GMap. For example, I want to save the location are of NewYork city and once any vehicle entered in this area then we will get an alert. Vehicle updating his information through GPS.
Please suggest me if anyone having some experience about it.
I'm not sure what you mean exactly by "save the specific are from the GMap".
If you mean that you'd like to save a 'viewport' then you could retrieve the viewport coordinates for a particular search and use that as a defined area. Viewports are just large squares though, so this will include areas that are not 'New York City'
If you want to be more precise - i.e. to flag a car as it enters Manhattan, you would need a more detailed KMZ for the Manhattan New York City area.
The New York City Department of City Planning (DCP) provide KMZ's of all the boroughs which could be used to achieve a more accurate view of the area of interest. You could stitch them together to create an 'official' NYC city limits polygon.
https://www.google.com/fusiontables/DataSource?dsrcid=1767628
To determine if a vehicle has entered any of these areas you would need to perform a 'Point-in-Polygon' test against the KML polygon(s).
There are previous discussions on how to do that Here and Here
Hope that helps