I have a client that is asking us to create a Mileage Reimbursement Form which interacts with a Mileage Calculator (possibly from the internet)(although I was wondering if purchasing a professional software would let us raid the SQL tables). Specifically they want the ability to type in a starting and ending city and state in two or four fields and have the resulting mileage post automatically into the Trip Mileage fields. The last steps would be a Total Mileage field and a field that multiples that # by the reimbursement amount. The first step is the one that has me stuck.
Question
Question
Answer
You can use Google Maps Javascript API v3. The Geocoding Service can take the start/end locations and convert them into their actual geographic locations and then the Directions Service can be used to calculate driving distance.
I did a quick search as well and came across the Google API. The downside to using the Google API is that per the usage agreement you 'must' display a Google map showing the route after you provide the start and end points. Didn't sound like that was the intent. Also, I would agree with Kenneth in that the route selected does not necessarily depict the route actually driven. That and mileage between 'cities' is almost too vague to calculate. Just my two cents worth...
Good points, Cliff. In most cases though, the actual route taken doesn't necessarily matter as most companies will just pick the most cost effective route to reimburse the driver. Obviously some companies may have their own policy for this though so there are a variety of factors that may come into play when it comes to deciding how best to implement this. Also, regarding the vagueness of distance between cities, the nice thing about the Geocoding service is that it can take actual addresses and not just cities.
Replies
Interesting idea, but I dont think it would be too effective. Mileage can be tricky. I would imagine using an embedded Google Maps widget might allow you to get information about the distance, but essentially, mileage can vary greatly depending on your route. You could set up a form though with a database table that has approved mileage values for each location to each other location.
You could easily store the total reimbursement amount in the DB, or use some Javascript which is easy to find on LF Answers to calculate the mileage.