Using the web service sounds like a good idea, but it wouldn't work directly from JavaScript code, would it? All I see in the docs is straight JSON output, not JSONP. I tried adding a callback parameter to the sample JSON request URL in the docs:
http://maps.google.com/maps/api/directions/json?origin=Chicago,IL&destination=Los+Angeles,CA&waypoints=Joplin,MO|Oklahoma+City,OK&sensor=false&callback=foobar<http://maps.google.com/maps/api/directions/json?origin=Chicago,IL&destination=Los+Angeles,CA&waypoints=Joplin,MO%7COklahoma+City,OK&sensor=false&callback=foobar> But it ignored the parameter and still gave me straight JSON. GDirections does not use this API but uses a private API that does support JSONP. If we watch the traffic from this GDirections example: http://code.google.com/apis/maps/documentation/javascript/v2/examples/directions-simple.html It makes a call to this URL: http://maps.google.com/maps/nav?key=ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA&output=js&doflg=ptj&dirflg=d&mapclient=jsapi&q=from%3A%20500%20Memorial%20Drive%2C%20Cambridge%2C%20MA%20to%3A%204%20Yawkey%20Way%2C%20Boston%2C%20MA%2002215%20(Fenway%20Park)&callback=_xdc_._1ga8gean1<http://maps.google.com/maps/nav?key=ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA&output=js&doflg=ptj&dirflg=d&mapclient=jsapi&q=from%3A%20500%20Memorial%20Drive%2C%20Cambridge%2C%20MA%20to%3A%204%20Yawkey%20Way%2C%20Boston%2C%20MA%2002215%20%28Fenway%20Park%29&callback=_xdc_._1ga8gean1> and that call does return JSONP output. I don't think the TOS would allow calling that URL directly, would they? So it seems that to use the web service from JavaScript code, Richard would need to run it through a proxy on his server to avoid cross-domain Ajax restrictions. That would work, but wouldn't it also imply that any quotas and rate limits would apply to his server (i.e. to all of his visitors combined)? -Mike On Wed, Jun 9, 2010 at 4:51 AM, Andrew Leach <[email protected]>wrote: > On Jun 9, 11:39 am, "rich...@home" <[email protected]> wrote: > > > > Is there an official (ie. not likely to change) way to get the encoded > > polyline string from a polyline object? > > No, there is nothing in the documentation. That's unsurprising, > because it's considered that in creating a line you supplied its > vertices. It doesn't envisage getting a line from GDirections and > wanting to do something else with it, as well as putting it on a map. > > > If not, do you suggest that I fetch the points using > > polyline.getVertex() and then re-encode the points ready for passing > > to the elevation API? > > I wouldn't suggest that. I'd suggest ditching GDirections (which > doesn't allow you to do what you want to do) and substituting a call > to the web service: > http://code.google.com/apis/maps/documentation/directions/ > That does mean that you would need to do all the work GDirections does > in displaying the line and results table, etc, but it gives you the > line in a reliable manner. Displaying the table is covered by Mike's > tutorial at http://econym.org.uk/gmap/steps.htm although that does get > its data from GDirections. But it probably wouldn't be difficult to > adapt. > > -- > You received this message because you are subscribed to the Google Groups > "Google Maps API" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<google-maps-api%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/google-maps-api?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Google Maps API" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-maps-api?hl=en.
