I would like to get a list of all cities I might pass on my way between point A and point B
Input -
point A as origin
point B as destination
Output:
Route between point A and point B (that's obvious)
AND
list of cities / towns / places that are closer than X miles to my route.
I would like to present the user a list of possible waypoints to consider (points of interest, historic sites, parks, etc)
Any ideas how to do that?
I believe you'd need to do this in a two-stage process:
The first step would be to calculate a polyline representing the route between A and B (as you say, that's obvious). You can do this using the Bing Maps REST (http://msdn.microsoft.com/en-us/library/ff701717.aspx) or SOAP (http://msdn.microsoft.com/en-us/library/cc966826.aspx) routing services, for example.
When you request the route from either of these services, make sure you specify that you want the full route path to be included in the results (rpo paramter for REST or RoutePathType.Points parameter for SOAP). This will give you an array of all the points that are used to construct the routepath - otherwise you'll just get a summary of itinerary points (i.e. only those points on the route at which you need to do something - change roads etc.)
Once you've got the array of points, step two is to determine all those locations that lie within distance x of the path drawn between these points. While there are many webservices that allow you to query for places lying within x distance of an individual point (including the Bing Maps search service and the geonames findNearby service, for example), I'm not aware of any webservices that provide this functionality, so you'll have to provide it yourself.
One way of doing so would be to use SQL Server 2008 or SQL Server Azure, loaded up with the geonames allCountries data dump from http://download.geonames.org/export/dump/. You could then construct a LineString geometry from the points in your routepath, and query the list of places in the database with a query such as:
SELECT * FROM allCountries WHERE Location.STDistance(#RoutePath) <= 1000;
Johannes Kebeck posted an example using this approach based on the Bing SOAP Route service and SQL Azure, which you can find here: http://jkebeck.wordpress.com/2010/06/26/find-near-route-for-bing-maps-powered-by-sql-azure-spatial/
Related
I'm using the Google Maps API Web Services Directions API or the Distance Matrix API to find the travel distance and time between locations.
It seems that the API only supports calculation of the route between one origin and one destination. (In case of the Distance Matrix API, multiple combinations directly between origins and destinations are computed.)
My case is that I would like to know the route (really, just traveling time and distance) of a multiple-leg journey along a series (as in an ordered array) of locations.
So, considering four locations, A, B, C, D, I know how to compute the route between any pair, A-B, A-C, A-D, B-C and so on. I want to compute the route of A-B-C-D or A-C-D-B or A-D-B-Cand so on. I supply the route and the order of the legs, so I'm not asking to solve the Traveling Salesman Problem.
Is this possible with the Google Maps Directions API or Distance Matrix API?
Obviously, I can chain the locations myself, so ask for the routes of the individual legs in separate calls, and then add them together in the desired order: A-C + C-D + D-B becomes A-C-D-B. I'm hoping that it's possible with one call.
(I've looked for similar questions, but haven't found this exact one.)
Thanks to #geocodezip, the answer is to add 'waypoints' between the origin and the destination, as described in the documentation of the Directions API.
For example, the request https://maps.googleapis.com/maps/api/directions/json?origin=Boston,MA&destination=Concord,MA&waypoints=Charlestown,MA|Lexington,MA calculates the route between Boston and Concord via Charlestown and Lexington.
And the Traveling Salesman Problem is partly being solved as well, per
By default, the Directions service calculates a route through the provided waypoints in their given order. Optionally, you may pass optimize:true as the first argument within the waypoints parameter to allow the Directions service to optimize the provided route by rearranging the waypoints in a more efficient order.
I am trying to find any solution that can calculate distance between point A and point B BUT including information about country's border.. I checked Google Maps and Bing Maps APIs - both of them don't provide such features..
Any suggestion? Thank you in advance
First you can create a database of country boundaries. Country boundaries are easy to find online. Here is one source: http://www.diva-gis.org/Data
You can upload these into SQL 2008/2012 or Azure (express version is free) using the Shp2Sql tool here: http://www.sharpgis.net/page/Shape2SQL.aspx
Then using Bing Maps you can calculate a route and get the route point's. You can use the route points to create a LineString object and do an intersection test against the country data to get all the countries boundaries that line passes through. Then you can go through each resulting country and crop the line to the borders of the country. With the crop line you can then measure it's length. All of this can be done with the spatial tools in SQL. Here are some useful links.
http://msdn.microsoft.com/en-us/library/ff701713.aspx
http://technet.microsoft.com/en-us/library/bb933901.aspx
http://technet.microsoft.com/en-us/library/bb933962.aspx
http://technet.microsoft.com/en-us/library/bb933895.aspx
I have a number of target points on the map and a source location. I need to find the target point closest to the source location. The trick here is that "closest" means the shortest route. I can't use a simple crow fly distance.
This is essentially a one-to-many routing problem. I can get the answer by running a routing API call for each pair of points but that would be too slow and will blow up API usage.
Is there a way to do it with a single request using Google Maps API (I am ok paying for it if necessary)?
If yes, then what are the limits to the number of points, the request frequency, etc?
If no, is there another service that can do it?
Say I have a lot of points (thousands). Is there a way to upload them somehow and only use the source location in my requests?
You should take a look to Distance Matrix Service
You can specify a starting point and an end point (even intermediate waypoints), then get the distance in kilometers / miles by route.
To answer your questions :
Is there a way to do it with a single request using Google Maps API (I am ok paying for it if necessary)
Yes you can, just use the service given below
If yes, then what are the limits to the number of points, the request frequency, etc?
To quote the Usage limits and requirements :
The following usage limits are in place for the Distance Matrix service:
Maximum of 25 origins or 25 destinations per request; and
At most 100 elements (origins times destinations) per request.
Requests are also rate limited. If too many elements are requested within a certain time period, an OVER_QUERY_LIMIT response code will be returned.
Say I have a lot of points (thousands). Is there a way to upload them somehow and only use the source location in my requests?
I'm not sure what you really want, but you can define a point as "source location", then load it (from SQL, KML etc...), then load the targets and call the service to find which one is the closest.
I am working with a college to develop their campus iOS app. One of the app's features is the ability to determine which of the campus bus routes are most applicable to getting to a destination (as well as a listing of when the bus arrives, etc).
If I have sets of long/lat data representing the stops of a route, what is the easiest way to determine the closest route to a long/lat destination point? I have over 10 roues to consider.
If you want to determine the closest point to a route, you can use the Distance to a Ray or Segment formula using a lat-lng as the reference point.
There is another option, if you are using a Google Map, because the Terms of Service require that the service be used in the context of a Google Map; you may want to consider the Google Maps Distance Matrix Servicedev-guide. The service allows you to submit a request with an origins property, which must be an array of google.maps.LatLng starting points and a destinations property, which must be an array of google.maps.LatLng ending points. The DistanceMatrixServiceapi-doc also allows you to define a TravelModeapi-doc, which may be one of: BICYCLING, DRIVING, or WALKING. It has the advantage over simple distance calculation, because it accounts for the natural activity of traveling from one point to another using the existing network of streets.
I've got a page that has a map with a starting and ending location. I run a route between them to get the nifty line showing the route. I'm currently using Bing but have attempted with Google as well. I'd like to know which states this route passes through so I can then overlay those states with specific information.
Any suggestions on how to obtain this would be most appreciated.
I'm using the AJAX SDK's for both Bing and Google. Handling all the local stuff with js/jquery.
You can use a reverse geo-code request on the Google Maps API to determine what state a particular point is in. So I imagine you could process your array of points returned with the directions request and pull out the state for each one.
In the v2 API, this would be:
results.AddressDetails.AdministrativeArea.AdministrativeAreaName
I think this is a bit more intuitive in v3. You can examine the AddressComponents array in the results to find the appropriate type:
{
"long_name":"California",
"short_name":"CA",
"types":["administrative_area_level_1","political"]
}
You could optimize the reverse geocoding by using divide and conquer on the array of positions on the route (if the state is the same for the first and middle position, then don't do reverse geocoding on the intervening points).
The MapQuest Directions web service has a stateBoundaryDisplay flag that will explicitly put state boundary crossings (ie "Crossing into statename") in the narrative. You could easily pull just that info from the json/xml response with a text search of the narrative steps.
http://www.mapquestapi.com/directions/#advancedoptions
Hope that helps.
Roman
You could create your own service utilizing a shapefile and a library like SharpMap or a geodatabase like mysql spatial, sql server spatial, etc. Then you simply just need to run an intersection query to discover which states your route runs through. This approach would work for any polygon set, so you could easily extend the solution to counties, voting district, school districts, etc.