title: Elevation service UNKNOWN_ERROR
body: <p>I'm having difficulty with the Google maps V3 JavaScript elevation service.</p>
  
  <p>According a google groups posting ( <a href="https://groups.google.com/forum/#!msg/google-maps-js-api-v3/Z6uh9HwZD_k/G1ur1SJN7fkJ" rel="nofollow">https://groups.google.com/forum/#!msg/google-maps-js-api-v3/Z6uh9HwZD_k/G1ur1SJN7fkJ</a> ), it appears that if you use getElevationAlongPath() it compresses and sends the entire path to the Google server as an Ajax GET request and subsamples it on their server.  This means that if you have a large number of path segments the encoded URL exceeds the maximum URL length and the request fails with UNKNOWN_ERROR.</p>
  
  <p>Can anyone confirm that this is a URL length issue?</p>
  
  <p>I've tried doing my own subsampling along the path and sending just the points I want elevation data for as a getElevationForLocations() request.  This does seem to be an improvement, but I'm still getting some UNKNOWN_ERROR responses.  These occur unpredictably.  Sometimes a request with 400 points returns successfully. Other requests will fail with only 300 points passed. I'm guessing that this still a problem with URL length (presuming getElevationForLocations() also sends URL-encoded data to Google).</p>
  
  <p>The documentation says that "you may pass any number of multiple coordinates within an array, as long as you don't exceed the service quotas."  This doesn't seem to be the case.</p>
  
  <p>Does anyone have any suggestions for a reliable way to get a large number of elevation data points (500?) from a long path?</p>
  
  <p>Thanks,
      Colin</p>
  
  <hr>
  
  <p>After a bit more digging, this seems to be the situation.</p>
  
  <p>The JavaScript API for elevation uses the HTTP elevation service behind the scenes.  The HTTP elevation service docs do say that requests are limited to 2048 characters.  However, if you're using the HTTP service directly, you build you're own URLs.  This means you can check the length before sending.  If you use the JavaScript API, the URL is built for you, but the API code doesn't check the URL length before sending.</p>
  
  <p>The call end-point URL and the necessary parameters take up 78 characters leaving 1970 for the encoded points.</p>
  
  <p>This is where it gets messy.  The number of characters in an encoded point varies with the size and precision of the lat and lng values. Generally, somewhere between 8 and 12 characters per point.  An added complication is that some of the characters used in the path encoding may need URL-encoding - further increasing the number of characters needed per point by an unknown, but potentially significant amount (2 extra characters for each path character in need of URL encoding).</p>
  
  <p>All of these complications mean that its theoretically possible for a call to result too long a URL with just 55 points - very, very unlikely though. A safe limit is probably 150 points (but this may still fail occasionally).  200 should work most of the time.  250 should be about the maximum.</p>
  
  <p>In reality, from a small number of tests:
   - 200 worked every time
   - 300 usually works
   - 400 sometimes works</p>
  
  <p>The discrepancy between the calculation and the tests suggests that the JavaScript API may be doing some further form of compression or I've got something wrong in calcs?</p>