Talking to the GoogleMaps APIs
This subject is already extremely well documented here, so I’ll just point you to the relevant code.
- The call to GoogleMaps is at #7# in Geodesic.Resolve.Resolve.
- The resultant JSON object is made into a .Net object with System.Web.Script.Serialization.JavaScriptSerializer.
This is technically obsolete, but trying to figure out how to use DataContractJsonSerializer was beyond my patience and JavaScriptSerializer #21# did the job perfectly. - We parse the resultant object crudely in Geodesic.GetLocations.GetLocations #22# for geocode requests and Geodesic.GetRoutes.Getroutes #23# for Travel requests.
- Notice that in GetRoutes, we don’t parse the details of each step by default, they add nothing to the information we need for this application (simply the distance and the duration).
- Perhaps a word on Google’s Terms Of Service. In a nutshell, you may not make more than 2’500 geocode requests in a single 24-hour period. If you exceed this you will receive a 602 return code, as you will if you make requests too quickly in succession. GeodesiX respects this and slows down automatically if it receives a 602.
- The corollary is that information obtained from Google is ‘valuable’ and we should at all costs avoid asking for it again. GeodesiX does this by saving the cache to a ‘very hidden’ worksheet #24# and re-loading this cache when a workbook is re-opened #25#. This may be defensible, but it is barely in line with the T.O.S.
- The moral is: Please use this addin responsibly. I have no doubt that Google couldn’t care less if you geocode a few dozen locations occasionally and keep the answers. On the other hand, using GeodesiX to perform bulk geocoding is immoral, irresponsible and could potentially spoil a very useful service that benefits the majority.
Again, please play fairly and think of others.