You need to assign the distance value to hidden field in the response/callback method
Quote:
function (response, status) {
of Google Maps service "google.maps.DistanceMatrixService". Note that getting distance from google service is an async process.
There is a trick to do this.
1. First create one html input button which is used to get calculate the distance and is visible to the end user.
2. Create another asp.net button which stays hidden (style=dispay:none) with a server side click event at server side.
3. Now on onclick event of input button, calculate the distance and get the response set in hidden field. Also, jQuery trigger the asp.net button when you get the distance in the response and everything valid.
4. On server side event of the asp.net button get the distance from the hidden field.
Hope this helps.