Google Directions API - Route to a wider area - javascript

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.

Related

Through the Google Maps API it is possible to know the provinces, regions that fall within an area that is obtained with a radius from a given point?

if through the Google Maps API it is possible to know the provinces, regions and nations that fall within an area that is obtained with a radius of x km from a given point?
No, it is not possible. The Google Maps API does not provide the ability to dump all features within a particular geographic area and only allows searching for a particular type of place.
See https://developers.google.com/maps/documentation/places/web-service/search for more information.

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

Make Google Marker follow road

I'm currently using Google Maps to display data from over 500 vehicles on a map. Currently, vehicles are updated on average every 60 seconds. I currently use some JavaScript/jQuery to animate each marker from its old position to its new position.
Because the data isn't coming in very frequently it often means that each marker would animate across many buildings, rivers, lakes etc. What I'd like to do is have these markers follow the road, however I'm worried that in doing so it could become expensive.
I see that the Google Maps Directions API would allow me to do this. If I calculate the route from the marker's old position to its new position it would split the route up into many different lines and I could have the markers animate across them. However, with 500 vehicles updating every minute, that's 500 direction requests every minute. Somehow I don't think I'd even survive on the Google Maps for Business API.
If anyone has any ideas as to how I could do this without spending billions, I'd appreciate it.
Thanks
It seems to me that you would only query the Direction API once for each 500 vehicles as long as the destination never changes. You may still run up against API rate limiting nonetheless.
You're going to need to reduce your set of 500 down to something more manageable. I would probably start by only performing animations/calculations on markers that are only immediately visible within the given map viewport. You would still need to update all marker positions in case a marker is about to come into your viewport, but you don't necessarily need to manage this with an actual google.maps.Marker object for each vehicle. You could instead keep track of positions in a separate data structure so you're not having to constantly draw to the map.
As an aside, you may also want to explore clustering options for your markers as having more than a dozen or so on screen at once becomes visually unmanageable.

Google maps api v3 polylines snap to nearest street

Assuming i have a list of positions from a GPS unit loaded into a database. Now i would like Google maps to show these positions, which works just out of the box like this
new google.maps.LatLng(57.046085209585726, 9.917740747332573),
new google.maps.LatLng(57.04606626648456, 9.918211475014687),
new google.maps.LatLng(57.04656251706183, 9.917992874979973),
new google.maps.LatLng(57.04649009741843, 9.918401995673776),
new google.maps.LatLng(57.04628427978605, 9.91844767704606),
new google.maps.LatLng(57.04613022040576, 9.91837676614523),
new google.maps.LatLng(57.045781994238496, 9.918353715911508),
new google.maps.LatLng(57.045685979537666, 9.918150706216693),
new google.maps.LatLng(57.0457204291597, 9.917718200013041),
new google.maps.LatLng()
The problem is. That the polylines cut corners and due to less correct GPS devices it will look like you walked through a building and swimmingpool to get to the other side of the street.
Is there any way i can make my positioning data from the database snap to the nearest street?
Thank you all
Jonas
Not that I am aware of.
You could try using the Directions API to request directions between the points but there is a limit of eight waypoints per request, you can break longer lists of points into sublists and make multiple directions calls but there are limits on the number of calls allowed to the service.
Another problem with this approach is if due to minor inaccuracies in your data or the map data you, for example, appear to be on the wrong side of the road it might generate spurious U turns and trips around roundabouts.
The standard Google map web user interface has a line drawing tool with a 'snap to road' option but this option was not included in the API version of the drawing manager.
I did submit an enhancement request http://code.google.com/p/gmaps-api-issues/issues/detail?id=3824&can=4&sort=-stars&colspec=ID%20Type%20Status%20Introduced%20Fixed%20Summary%20Stars%20ApiType%20Internal but no response yet. You could star the issue and/or create your own request since you issue isn't quite the same.

Placing markers for 6000+ locations using Google Maps (or some other web & mobile platform)

The closest example of what I'm trying to accomplish is a store locator. I have 6,000+ locations that need to be plotted onto a map of Canada.
My original plan was to use Google maps to place markers on each location, but it doesn't make sense to plot them all every time someone attempts to view the map, or various parts of the map.
How does one only put markers on the locations in view? Do I have to send the geo data of all 6000 locations to the client each time they load the map?
Is this doable with maps? (I'm sure it's got to be) Or is there a better service for this kind of thing?
Definitely do not draw all the locations at the same time if they are not all visible. Consider using MarkerManager (article here) or MarkerLight (code: http://gmaps-samples.googlecode.com/svn/trunk/manymarkers/, demo: http://gmaps-samples.googlecode.com/svn/trunk/manymarkers/randommarkers.html). If your initial map and data is such that all the markers would be visible initially, this is definitely the way to go.
You can also use the GEvent object (docs) to detect a "move" event, then check the current display coordinates, draw any that are in bounds. This is the best route if your initial map is too zoomed or small, and/or your marker set is too large to fit on the map's initial view. Your user will be moving the map around, so you can react to that movement and only draw the relevant markers. Take a look at http://econym.org.uk/gmap/gevent.htm for a list of other GEvent events (couldn't find an official list on the API), you might also want to watch "zoom" events.
The two methods can also be combined.
You can use getBounds() to determine the viewable portion of the map. I'd use this data to request from the server all locations within those bounds. Use the bounds_changed event to monitor changes to the viewport and request additional locations as necessary. You'll probably want to set either a minimum zoom level, or maximum number of results to avoid displaying too many locations than is reasonable. Eg, when the map is zoomed out to display all of Canada in a single view.

Categories

Resources