I am trying to get the height of the point in the coordinates to perform the calculations. The result is supposed to be placed in the text field. By the way, the server response is not processed, however. Even before sending a request to the server, an error occurs that lat is an unknown attribute. For everyone: the browser is Google Chrome. Please help me understand the reason.

<html> <head> <title>some_title</title> </head> <body> <b>Результат</b><br> <textarea cols="150" rows="50" id="result" value=""></textarea> <br> </body> <script src="https://maps.googleapis.com/maps/api/js?key=apiKey&libraries=geometry,elevation"></script> <script> var requestToServer = new XMLHttpRequest(); requestToServer.onreadystatechange = answerReciever; var elevator = new google.maps.ElevationService; elevator.getElevationForLocations([{lat:63.333, lng:-150.5}]); function answerReciever(response){ var d = new Date(); document.getElementById('result').value += d.toString() + '\n'; } </script> </html> 
  • I see you have at least two mistakes. 1 - create requestToServer , but do not start sending. 2 - create elevator , not enough brackets, it should be like this new google.maps.ElevationService() - Stepan Kasyanenko
  • 2. If you believe the dock, then everything is correct; I also copied the string from there. developers.google.com/maps/documentation/javascript/… For the link, see "Elevation service usage examples." - Nikita Nesmiyanov

1 answer 1

Understood. I incorrectly called the getElevationForLocations method. Correctly: getElevationForLocations ({locations: arrayWithLocationObjects}, loopbackProcessingFunction).

In addition, creating the requestToServer variable in the code is unnecessary. The getElevationForLocations method creates everything you need yourself and sends the same request to Google servers; you just need to create a function to handle the response.

Description of the getElevationForLocations method: https://developers.google.com/maps/documentation/javascript/reference?hl=en#ElevationService

LatLng object description: https://developers.google.com/maps/documentation/javascript/reference?hl=en#LatLng