google-maps-react icon indicating copy to clipboard operation
google-maps-react copied to clipboard

ElevationService

Open codemgf opened this issue 5 years ago • 0 comments

Hi all,

I need do return to my application the elevation of a determined point selected in the map. I've tried to use the code from google api documentations, with some modifications to my component. But no success. It doesn't return any error. But do not enter in the callback funcion. I've tried many different ways.

Is there any special way do deal with it in google-maps-react?

This is one of my tests:

onMapClick = (t, map, coord) => { 
    const { latLng } = coord;
    const lat = latLng.lat();
    const lng = latLng.lng();
    var alt = 1;

    const google = this.props.google;

    var elevator = new google.maps.ElevationService();

    // Initiate the location request
    elevator.getElevationForLocations(
        {
            locations: [coord],
        }, 
        function(results, status) {
            if (status === 'OK') {
                if (results[0]) {
                    alt = results[0].elevation;
                } else {
                    alt = 2;
                }
            } else {
                alert("Error while accessing Google Maps API Elevation");
            }
        }
    );

It always pass by all the code inside elevator.getElevationForLocations function and alt always returns 1, value I've set initially.

Thanks in advance for any help.

codemgf avatar Oct 01 '20 13:10 codemgf