title: GoogleMaps Optimize waypoints and relate to original sequence
body: <p>I'm using googlemaps api to route and optimize a set of waypoints from a Database.  The waypoints are fed in, in random order.  Once the waypoints are optimized via googlemaps to create a proper route order, I need a way to correlate them to the original sequence so I can update the route order in a database.  </p>
  
  <p>For example my original data from the DB might look like the below (LoadNum is blank to start):</p>
  
  <pre><code>    LoadNum Order address   City    State   Zip
     blank    1   456 Elm Street  Chicago IL  12345
      blank   2   123 Main Street Cleveland   OH  12345
      blank   3   678 Market Street   Beverly Hills   CA  90210
  </code></pre>
  
  <p>After GoogleMaps Optimizes the route the addresses could be changed a little to the nearest match on each of those streets, as in below with the ranges;</p>
  
  <pre><code>LoadNum Order address   City    State   Zip
         blank    2   120-160 Main Street Cleveland   OH  12345
         blank    1   200-300 Elm Street  Chicago IL  12345
         blank    3   678 Market Street   Beverly Hills   CA  90210
  </code></pre>
  
  <p>GoogleMaps also returns a route segment number that I want to assign as loadnumber in the database, but I don't have a way to guarantee the match.  If I could pass an identifier (OrderNumber) to googlemaps, and have it returned with that record that would be ideal, so even if the address has changed I know order number 'x' is stop 1.  </p>
  
  <p>Code snippets below, first is the JavaScript, near the bottom I'm capturing routeSegment and EndAddress into a variable (actually a text field for now so I can see it):</p>
  
  <pre><code> directionsService.route({
              origin: document.getElementById('StartBoxAjax').value,
              destination: document.getElementById('EndBoxAjax').value,
              waypoints: waypts,
              optimizeWaypoints: true,
              travelMode: 'DRIVING'
          }, function (response, status) {
              if (status === 'OK') {
                  directionsDisplay.setDirections(response);
                  var route = response.routes[0];
                  var string = [];
                  document.getElementById('&lt;%=JScriptParm.ClientID %&gt;').value = ""
                  var summaryPanel = document.getElementById('directions-panel');
                  summaryPanel.innerHTML = '';
                  // For each route, display summary information.
                  for (var i = 0; i &lt; route.legs.length; i++) {
                      var routeSegment = i + 1;
                      summaryPanel.innerHTML += '&lt;b&gt;Route Segment: ' + routeSegment +
                          '&lt;/b&gt;&lt;br&gt;';
                      summaryPanel.innerHTML += route.legs[i].start_address + ' to ';
                      summaryPanel.innerHTML += route.legs[i].end_address + '&lt;br&gt;';
                      summaryPanel.innerHTML += route.legs[i].distance.text + '&lt;br&gt;&lt;br&gt;';
                      //document.getElementById('JScriptParm').value += routeSegment;
                      document.getElementById('&lt;%=JScriptParm.ClientID %&gt;').value += routeSegment + ',' + route.legs[i].end_address + '|';
                     // string += routeSegment + ',' + route.legs[i].end_address + '|';
                     // document.getElementById('&lt;%=JScriptParm.ClientID %&gt;').value = string;
  
                  }
  </code></pre>
  
  <p>Then in code behind I would like to do a DB update where "AddressInDB matches Address returned from JavaScript".</p>
  
  <pre><code> protected void AssignLoadNum(string city, string state, string stop)
      {
          //Call Stored proc to update load number.
          SqlConnection conn = new SqlConnection();
          SqlCommand cmd = new SqlCommand();
          string connStr = ConfigurationManager.ConnectionStrings["FurnitureDB"].ConnectionString;
          conn.ConnectionString = connStr;
          conn.Open();
          cmd.CommandType = System.Data.CommandType.StoredProcedure;
          cmd.Connection = conn;
          cmd.Parameters.Add("@state", SqlDbType.VarChar).Value = state;
          cmd.Parameters.Add("@city", SqlDbType.VarChar).Value = city;
          cmd.Parameters.Add("@stop", SqlDbType.Int).Value = Convert.ToInt32(stop);
  
  
          cmd.CommandText = "UpdateLoadOrd";
          cmd.ExecuteNonQuery();
          //var dt = new DataTable();
  
      }
  </code></pre>
  
  <p>In my example the parameters are City and State, but that is not going to be specific enough.  The long and short of it is, is there a way to pass an identifying parameter through GoogleMaps Javascript API that will be returned/maintained, or is there another way to achieve what I'm after?  </p>
  
  <p>Thanks.  </p>