13

I am working on a quote calculator that will generate a quote based on mileage between various locations (amongst other conditionals). Up until two days ago, I had planned to use Google's Distance Matrix service until I discovered:

Display of a Google Map

Use of the Distance Matrix service must relate to the display of information on a Google Map; for example, to determine origin-destination pairs that fall within a specific driving time from one another, before requesting and displaying those destinations on a map. Use of the service in an application that doesn't display a Google map is prohibited.

I had hoped to use only the services that I require:

- Distance by Road Measurement between up to three different locations

- Address Autocomplete Service usable on an input box

- Accurate, reliable service that can provide multiple different routes to create an average distance

I know there are other methods available for this, but I doubt many can be as accurate and reliable as Google, I've found it challenging to find anything comparable to Google Maps for the purposes I require.

So, unless you guys can point me to something that I can use, my only option is to use a Google Map where I don't need it, adding additional loading time and altering the UX design I had planned.

Are there any free services available for what I require (preferably with a JS API)?

On a slightly different note

If I do use a Google map, would it have to be displayed immediately, or could I hide it and add an option to 'Show On Map', and have it .slideToggle revealed?

Dom
  • 2,275
  • 3
  • 24
  • 34

4 Answers4

12

Unfortunately for the Distance Matrix API, Google strictly says you NEED to display the map in your application:

Use of the Distance Matrix API must relate to the display of information on a Google Map; for example, to determine origin-destination pairs that fall within a specific driving time from one another, before requesting and displaying those destinations on a map. Use of the service in an application that doesn't display a Google map is prohibited. http://developers.google.com/maps/documentation/distancematrix/#Limits

However, what I think is more useful for your need is Google Directions API. The directions API allows you to cover your requirements.

The total distance is returned in the JSON object from the request.

You can select upto as many different locations to find distances between using the Waypoints in your search request. The distances between these locations are then returned in each "leg".

You can obtain the average distance from multiple different routes to your destination by specifying the alternatives parameter in your search request to true. See: http://developers.google.com/maps/documentation/directions/#RequestParameters

Best of all, there is no requirement from Google to display the Google Map in your application when using this service.

I should also mention the drawbacks to this service, if you choose to use it.

  1. The request time it takes to process your request will be slightly longer than if you were to use the Distance Matrix API.
  2. You'll have a lot of unneeded data in the return object, for instance the individual "steps" of the route in the returned json object is not necessary based on your application requirements.

Given the drawbacks, I'd still highly recommend looking into the Directions API for your application.

Suvi Vignarajah
  • 5,758
  • 27
  • 38
  • Thank-you, nice answer. Would I still be allowed to use the address autocomplete service on an input box without displaying a google map? – Dom Jan 11 '13 at 17:29
  • 1
    Ah I see what you mean, I'm not sure you can do that with the Directions API - but you can use the Places Library for this functionality: https://developers.google.com/maps/documentation/javascript/places#places_autocomplete. Made a quick jsFiddle to demo the autocomplete feature here: http://jsfiddle.net/svigna/Ev2Ft/. Is this what you meant by autocompleting addresses in an input box? – Suvi Vignarajah Jan 11 '13 at 18:15
  • Wow, I had no idea it was that simple, I stripped down googles Distance Matrix example to get the autocomplete functionality, your example is far simpler. Yes that is what I meant, thank-you, can the data from there be used in Google Directions API aswell? – Dom Jan 11 '13 at 18:36
  • 1
    Yup, you sure can. You can use javascript's `getElementById('inputID').value` or jQuery's `$('#inputId').val()` to get the values. Then pass them into your request url for Directions API as the `origin` and `destination` request parameters. – Suvi Vignarajah Jan 11 '13 at 19:43
  • 7
    Google Directions API now requires you to display a map. "Note: the Directions API may only be used in conjunction with displaying results on a Google map; using Directions data without displaying a map for which directions data was requested is prohibited. Additionally, calculation of directions generates copyrights and warnings which must be displayed to the user in some fashion. For complete details on allowed usage, consult the Maps API Terms of Service License Restrictions." – charliefortune Feb 05 '13 at 22:06
  • Thanks for that note @charliefortune, that must've been a new restraint from Google. I assume the only way to bypass that is by purchasing their business API? – Suvi Vignarajah Feb 08 '13 at 15:52
  • Ahhh poop, I give up. Will modify UX to include a map for some reason. Changes a lot, thanks Google! If you weren't so awesome I'd be angry. – Dom Mar 15 '13 at 15:05
1

I don't know if Google Static Maps count as a map, but it should, since it's a Map and from Google. You could calculate the route and then show it as an image from Static Maps. No extra map loading times required. Only one image.

https://developers.google.com/maps/documentation/staticmaps/#Paths

jfvoliveira
  • 104
  • 2
  • 7
1

Many developers have been able to do this with the Bing Maps REST routing service http://msdn.microsoft.com/en-us/library/ff701705.aspx. It requires a bit more development but works well. Here is an example: http://code.msdn.microsoft.com/Bing-Maps-trip-optimizer-c4e037f7

rbrundritt
  • 16,570
  • 2
  • 21
  • 46
0

Streetmap and arcserver can solve a vehicle routing problem but it's not free. Read more here: http://www.esri.com/data/streetmap.

Micromega
  • 12,486
  • 7
  • 35
  • 72