Batch Calculations
1. Import header files
#import <NavinfoKit/NavinfoKit.h>
2. Configure APIKEY
Refer to Project Configuration Instructions.
3. Define NavinfoRouteSearch
Define the master road object NavinfoRouteSearch and inherit the search protocol <NavinfoRouteQueryDelegate>.
4. Construct NavinfoRouteSearch
Construct the main search object NavinfoRouteSearch and set the proxy.
NavinfoRouteSearch * routeSearch = [[NavinfoRouteSearch alloc] init]; routeSearch.delegate = self;
5. Set up to initiate batch calculation parameters
where orig (starting point coordinates) vias (path point coordinate set can be empty) dest (end point coordinates) query (calculation type).
- (id)initBulkQueryWithorigs:(NSArray < NavinfoLonlat * > * _Nonnull)origs dests:(NSArray <NavinfoLonlat * > * _Nonnull)dests;
6. Initiate a batch calculation
Initiate a calculation query by calling the startSearch method of NavinfoSearchRoute.
[search startSearchWith:query];
7. Processing data in callbacks
When the query is successful, it will enter the callback function, and the callback function can get the result of the calculation.
Description:
Get a batch plan set via response.routes
- (void)onRouteSearch:(NavinfoRouteSearch * _Nonnull)routeSearch result:(NavinfoRouteResult * _Nullable)result error:(NSError * _Nullable)error { NSLog(@"----> onRouteSearch"); }
8. Processing failed queries
When the retrieval fails, Error returns, and the reason for the failure is obtained by the callback function.
- (void)onRouteSearch:(NavinfoRouteSearch * _Nonnull)routeSearch result:(NavinfoRouteResult * _Nullable)result error:(NSError * _Nullable)error { NSLog(@"----> onRouteSearch"); }
Run the program, the effect chart is as follows.