PC*MILER|Connect includes simplified functions for distance calculation between an origin and a destination, using PC*MILER's industry standard mileage database.
- Create a new trip by calling PCMSNewTrip.
- Call PCMSCalcTrip to return the distance between an origin and destination using the trip’s current routing type. (The default is practical routing.)
- Call PCMSDeleteTrip to free all resources associated with a trip handle created with PCMSNewTrip.
- Repeat with as many origin-destination pairs as you want.
Additional Options
With simple distance calculations, you can also:
- Change the routing type by calling PCMSSetCalcType.
- Get the trip's duration in minutes by calling PCMSGetDuration.
- Validate your city names and ZIP codes using the function PCMSLookup with option 5.
Sample code to calculate the distance between Chicago, IL, and New York, NY, using three different route types.
void RunRoutes(PCMServerID server) { long minutes; long hours; long miles; int matches; /* Note: Server must already be initialized. */ Trip trip = PCMSNewTrip(server); /* Calculate the distance using default calculation */ miles = PCMSCalcTrip(trip, “Chicago, IL”, “New York, NY”); printf(“Practical: %f\n”, miles / 10.0); /* Calculate the distance using shortest algorithm */ PCMSSetCalcType(trip, CALC_SHORTEST); miles = PCMSCalcTrip(trip, “Chicago, IL”, “New York, NY”); printf(“Shortest: %f\n”, miles / 10.0); /* Calculate the distance avoiding toll roads */ PCMSSetCalcType(trip, CALC_AVOIDTOLL); miles = PCMSCalcTrip(trip, “Chicago, IL”, “New York, NY”); minutes = PCMSGetDuration(trip); printf(“Toll Avoid: %f miles\n”, miles / 10.0); /* Show the duration in hour:minute notation */ hours = minutes / 60; minutes = minutes % 60; printf(“Duration: %ld:%ld\n”, hours, minutes); /* Check the spelling of a city and ZIP */ matches = PCMSLookup(trip, “San Fran, CA”, 5); printf(“Matching city names: %d\n”, matches); }