Finding Locations with the MapPoint Web Service Find APIs - Finding Points of Interest Along a Route
(Page 4 of 4 )
To find points of interest along a given route, use the FindServiceSoap.FindNearRoute method. The FindNearRoute method works only with data sources that have the CanFindNearby capability. As with the FindNearby method, only the point of interest data sources supplied by data vendors such as NavTeq and Acxiom have this capability; data sources such as MapPoint.NA and MapPoint.EU do not support the FindNearRoute method.
You can read more about calculating routes using RouteServiceSoap in Chapter 7.
Like any other find service method, the FindNearRoute method also takes a specification of type FindNearRouteSpecification class. The FindNearRouteSpecification object takes information, such as the data source name, input route (as a Route object) around which you want to find points of interest, and distance to be covered along the route, and uses it to find points of interest and entity types you want to find. Table 6-5 gives an idea of the fields presented in the FindNearRouteSpecification object.
Table 6-5. Fields in a FindNearRouteSpecification object
| Field | Description |
| DataSourceName | The data source name as a string |
| Distance | The distance from the Route property |
| Filter | The filter ( FindFilter object) to apply to the results; that is, the specific entity type, properties, and values that the returned results must match |
| Route | The route from which the points of interest are searched |
| Options | The search options ( FindOptions object), which include the range of results and a flag to identify which objects are desired in the returned results |
Say you want to find all the coffee shops along the route that you are planning for a road trip. First, calculate your route using the RouteServiceSoap class; next, call the FindServiceSoap.FindNearRoute with one of the point of interest data sources (I chose to use MapPoint.FourthCoffeeSample ) and the entity type name for coffee shops, FourthCoffeeShops , as follows:
FindServiceSoap findService =
new FindServiceSoap();
findService.Credentials =
new System.Net.NetworkCredential(myMapPointUserId,
mySecurePassword);
RouteServiceSoap routeService = new RouteServiceSoap();
routeService.Credentials =
new System.Net.NetworkCredential(myMapPointUserId,
mySecurePassword);
//Route between two locations
LatLong[] latLongs = new LatLong[2];
latLongs[0] = new LatLong();
latLongs[1] = new LatLong();
latLongs[0].Latitude = 52.5;
latLongs[0].Longitude = 13.1;
latLongs[1].Latitude = 52.51;
latLongs[1].Longitude = 13.11;
//Calculate route
Route myRoute =
routeService.CalculateSimpleRoute(latLongs,
"MapPoint.EU",
SegmentPreference.Quickest);
//Create near route specificiation
FindNearRouteSpecification findnearroutespec =
new FindNearRouteSpecification();
findnearroutespec.DataSourceName = "MapPoint.FourthCoffeeSample";
findnearroutespec.Filter = new FindFilter();
findnearroutespec.Filter.EntityTypeName = "FourthCoffeeShops";
findnearroutespec.Distance = 20;
findnearroutespec.Route = myRoute;
FindResults foundResults;
foundResults = findService.FindNearRoute(findnearroutespec);
//Process the results to display on a map
...
This code finds the coffee shops around the specified route within 20 miles from the beginning of the route using the MapPoint.FourthCoffeeSample data source; you could use different point of interest data sources from Acxiom or NavTech or even your own data source.
Finally, note that the distance must always be greater than 0.1 miles (0.160934 kilo meters) and less than 25 miles (40.2336 kilometers).
Please check back next week for the continuation of this article.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
|
This article is excerpted from chapter six of the book Programming MapPoint in .NET, written by Chandu Thota (O'Reilly; ISBN: 0596009062). Check it out today at your favorite bookstore. Buy this book now.
|
|