Google Maps Distance Calculator api - google-maps-api-3

I found this cool feature in google map that allows to calculate distance between two points of interest. It doesn't simple calculate the linear distance petween points but allows to draw on the Map the route on the map. Have you ever used it? Do you know where i can find the API documentation?

Google's Maps API is publicly available. You might be looking for DistanceMatrix. You could then use Polyline to create the route, and DrawingManager to draw it.

Related

Google Maps - Follow Path Of Travel

I am working with a security company that has a patrol car travel around a neighborhood. Every 30 seconds, they record a GPS coordinate/point which I can download and use. I'm trying to map a 'path of travel' for the patrol vehicle using Google Maps API.
I understand how to map (marker) all the points using the Google Maps v3 API. I also understand how I can do a driving route between a few points using directionsService. According to Google and StackOverflow, the maximum number of waypoints is 26.
The problem is that I have dozens of these points (1 hour = 120 points). I can't just draw a polyline between the points because I need it to show the path of travel on the actual street - not as the crow flies between 2 points. Also, I don't have 10K to purchase an Enterprise license.
Any ideas on how this might be accomplished or am I SOL? Can you draw 120 multiple 'routes' on the same map? Speed is not important here.
Thanks,
Mike
Can you draw 120 multiple 'routes' on the same map?
You can. When you want to draw the routes by using the DirectionsRenderer you must use a separate DirectionsRenderer-instance for each route.
Another approach: request the routes via the DirectionsService, but use a custom Polyline to draw the route. Each time you get a new route you'll only have to push the points of the new route to the path of the polyline.

Google Maps API V3 -> Utilize MarkerCluster but have the clusters themselves be specific to a drawn polygon/region?

Ok, let me preface this question with the fact that I have created a lot of google maps, but they have been strictly markers and polylines denoting routes and a couple with some handler interaction.
Now I am looking to show basically a map of the world, mostly North America and I want to split this continent into my predefined regions with some lats/lngs that I have. Using these regions I want to draw something like a polygon with a light opacity and different color per region.
I then want to use marker clustering but I want the clusters to be specific to these regions. I have looked around but I haven't found an example like this. I have seen pages that say you can do this but not how you would go about doing this. Again, I am definitely a noob when it comes to drawing polygons and using the marker cluster. I know this question is fairly vague but just looking for an example/idea to start off of, and more so I don't want to write a bunch of code against this specific api and then find out that it is not possible.
Any ideas or suggestions are greatly appreciated....Thanks.
It can be done, but will require a rewrite of the MarkerClusterer (probably will simplify it).
You will need to determine how you are going to represent and load the cluster boundary polygons (KML, GeoJSON, native Google Maps API v3 polygons) and probably use the google.maps.geometry.poly.containsLocation(point:LatLng, polygon:Polygon) instead of LatLngBounds.contains to determine which cluster "owns" a marker.

Finding streets (get their coordinates) and calculating distances between markers

I have trouble finding any information on how to use the API to:
Search for streets and get some clickable results that returns a LatLng object or something (at least coordinates). So If I search for a street and click on a result, I'll pan to that street (for example).
How can I calculate distance between markers? and possibly, draw lines between them.
All I get is the API but no guides so it's fairly hard figuring out what types to use.
Here is a fiddle showing how this can be achieved:
http://jsfiddle.net/foxwisp/vQGMr/1/
To convert street names to lat/lng you need to use a Geocoder such as the one provided by Google Maps API.
Then, when you get back the results from the geocode, you use the lat lng properties to create a marker. Once your first marker is placed, you repeat the process for your second street address. We nest these calls so that we can be assured of the order of execution due to their asynchronous nature.
Once we have our second marker we use Google's polyline function to draw a line between the two latlng marker points.
Then we use a slightly complicated mathematical equation to do some distance calculations and voila.
The Google Maps API is fantastically documented, hopefully this fiddle will put it into context for you and you can explore each element step by step by reviewing functions and properties in the documentation

google maps v3 determine which states are within boundaries of circle overlay

Is there a way to determine which states are within circle overlays created by google.maps.Circle? Perhaps using reverse geocoding and getBounds or contains? Does Google provide a way to do this (using the geocoder or some other method), or must a database of Latitude and Longitude points of states be used?
There doesn't seem to be an easy way to do this within Google Maps API.
You can use getBounds() to get a LatLngBounds object approximating the circle. Note though that getBounds() will return a rectangle that approximates the circle, so you might get inaccurate results. To do it more accurately, you'd need to calculate a bunch of points to approximate the circle using something like the Haversine formula in combination with the cirlce's center and radius. The more points you calculate, the more accurate the approximation.
Once you have your set of bounding points, you're still not exactly out of the woods. There does not appear to be a way to use Google's Geocoder API to return all the states in a LatLngBounds. So you'd have to calculate a bunch more points within the bounds and send individual reverse geocode requests for them. And you still might miss a state or two. Overall, yuck.
Another approach, that doesn't seem that much more appealing to me, but who knows: For each state, get lat/lng data for a bunch of rectangular bounds that, when all combined together, approximate the shape of the state. For each state, use intersects() to see if it intersects with your circle.
There may be other possibilities, involving Google Maps API or other technologies, depending on your use case.

Google apps script map api for distance calculation between two points

I know there is an api to calculate the distance between two points for google apps but what i am looking for is the google apps script api to calculate the driving distance not the direct distance between two points. Is there such an api?
Google directions API gives you the total distance between the source and destination.
try this
http://maps.googleapis.com/maps/api/directions/json?origin=nj&destination=ny&sensor=false
API Documentation here
One can follow the below link to get more details about it.
Calculating driving distance with google map api v2

Resources