I have a list of about 3000 points (lon,lat) and I need to create an application to find for any given position on map (lon, lat) all points from this list, which are reachable in 10 minutes by car.
I can easily calculate this task for distance in metres, eg. all points inside a circle, but I need to do it using duration in minutes, not distance in metres.
Which part of Google Maps API should I use?
It looks like you'll need to use the Google Distance Matrix. However, because of the limits, you'll probably need to get crafty with filtering the list of possible locations before sending the request.
100 elements per query.
100 elements per 10 seconds.
2,500 elements per 24 hour period.
You are trying to create a isochrone map
I would suggest something like this (a v2 example by Marcelo). The original is gone, here is a copy, and a version ported to the v3 API.
Start by drawing a circle (or not, but conceptually) with a radius that is greater that 10 minutes driving time (10 miles should work). Find all the points in your database in that circle (that are less than the radius/10 miles from the center point).
This should narrow down your points to a manageable number. Use the DistanceMatrix to further refine the number, eliminating those that are within the circle but greater than 10 minutes away.
proof of concept
uses the places search for locations, pares down the results to those in a 10 mile radius, then sends those results to the DirectionsMatrix, discarding any results with a duration of greater than 10 minutes.
Related
I have a MySQL database table with a series of points, which is a specific geometry data type (basically, a lat/lon coordinate). I need to get all the points that are close to some coordinates (close meaning to less that 1 km, let's say).
Now I am getting ALL points from the table and, from PHP, calculating which of them have a distance shorter than the desired distance (1 km).
The problem is that there a thousands of points, so the performance is very poor.
Is there a way to get only those close points directly from the database? I don't guess what function may help me.
Thank you!
I want to calculate distances between two coordinates but sometimes the origin coordinate is over / beyond the destination coordinate. And it is really problematic at one-way roads, because in this case the distance can be eg. 1 km to get back to the destination. In real life it is OK, but actually the real distance is only eg. 10 meters (if I could turn back on one-way roads). So only the direction is wrong.
I can resolve this problem if I call the API twice (origins=my_origin_coordinate&destinations=my_destination_coordinate and origins=my_destination_coordinate&destinations=my_origin_coordinate).
But is there a easier way to get both distance in one query? (to save my query limit...)
The distance matrix allows multiple results in a single query. You can do origins=my_origin_coordinate|my_destination_coordinate&destinations=my_origin_coordinate|my_destination_coordinate in a single request, which will give you both results. That won't really help with your quota though as the quota is based on "elements", and whether you do it in one query or two, it will be the same number of "elements".
So I have thousands of users with latitude and longitude. They check in with new coordinates every 30 seconds.
When they check in I need to send them the 100 people closest to them no matter how far away they are. In a crowded city this may be a radius of half mile. In the country it could take a radius of 100 miles to get 100 people.
It's easy enough to calculate the distance of each user from the user checking in and then do LIMIT 100. But that essentially does a table scan, calculates the distance between the checking in user and all other users in the table, sorts them by distance and then takes 100.
Won't be efficient at scale.
So what strategy can I use to scope the query to a subset of users and still get 100 results?
I don't think MySQL will be helpful for a longer duration. I'd recommend checking out the SingleStore database for your use case since it's efficient, scalable, and faster.
For your reference, Please go through the documentation by clicking the link here.
I've got courier tracking android app, which posts every 30s gps coords of the courier to a postgis database.
We need to calculate how many kilometers couriers do in order to provide them gas(petrol) refund.
How would you do that, fellow developers?
Sum the great-circle distances between consecutive measurement points to get an approximation (lower bound actually) for the distance traveled.
You can probably also get away (and get better numerical stability) with calculating the 3D ECEF positions from the spherical coordinates and summing the Euclidean distances between these points because it's pretty much impossible to cover a significant curvature on Earth in 30 seconds.
Folks,
How can I take a state and divide it into areas that are 50 miles in radius?
Perhaps there's a better way to solve my problem: I have a list of 700 locations with unique city names. Some cities are less than 50 miles apart. I need to reduce that list to the minimal number of locations that are no more than 50 miles away and that basically cover the nearby cities in the list. This way I can find the center radius ZIP code of each of the location on the reduced list and then search for "stores within 50 miles", which should return all 700 locations.
Update: I have 5000 products and 700 stores in different cities. I need to check inventory for ALL products. The site where I check it only shows inventory in stores that are within 50 miles of a given city. That mean that I need to make 3,500,000 requests. Hence, I am looking for a way to reduce 700 stores to a smaller number.
A simple algorithm which would work but is far from optimal. This starts with a list of candidate towns
Pick a town at random, draw a circle around that point
Remove all towns inside the circle
Repeat until there are no towns left
You could run it a few times to see if some runs produce significantly fewer resulting circles.
You can concatenate the binary value from the x- and y co-oordinates. Instead of a straight line it orders the points along a z-curve. Then you can compute the upper bounds with the mostsignificant bits. The z-curve is often use in mapping applications:http://msdn.microsoft.com/en-us/library/bb259689.aspx.