Google maps - find cities close to my route

邮差的信 提交于 2021-02-18 07:34:32

问题


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?


回答1:


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/



来源:https://stackoverflow.com/questions/5983462/google-maps-find-cities-close-to-my-route

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!