没有地图的Google Elevation可以显示

时间:2014-09-30 19:56:21

标签: javascript service elevation

我有一个req来获取给定纬度的高程剖面,长。我使用下面的代码。但是这段代码输出错误。我已将此与谷歌地图结果进行了比较。

function elevationVal(event) 
       {
         var lat = xval passed ;
         var lng = yval passed ;


        var altitudes = [];
        var locations = [];
        var latlng1 = new google.maps.LatLng(lat,lng);
        locations.push(latlng1);
         var positionalRequest = {
            'locations': locations
         }
         elevator = new google.maps.ElevationService();
         elevator.getElevationForLocations(positionalRequest, function(results, status) {
         var seaLvl  = results[0].elevation;
         eval01.setValue(seaLvl);
         if (status == google.maps.ElevationStatus.OK) {

          // Retrieve the first result
          if (results[0]) {
            var seaLvl = altitudes.push(results[0].elevation.toFixed(3));
             var eleval= results[0].elevation;
          } 
          else {
            alert("No results found");
          }
        } else {
          alert("Elevation SERVICE FAILED due to: " + status);
        }
      });
}

seaLvl或eleval中的任何一个都没有给出正确的高程值。如果有人开发了没有地图的代码,我会帮助我。

谢谢, RB

1 个答案:

答案 0 :(得分:1)

我做了一个jsfiddle尝试,它工作正常:http://jsfiddle.net/OxyDesign/0sgoqqco/

结果很好,如Google演示:https://developers.google.com/maps/documentation/javascript/examples/elevation-simple

$(document).ready(function(){
    $('#button').on('click',function(){
        var elevator = new google.maps.ElevationService(),
            denali = new google.maps.LatLng($('[name=lat]').val(), $('[name=lng]').val()),
            positionalRequest = {'locations':[denali]};

        elevator.getElevationForLocations(positionalRequest, function(results, status) {
            if (status == google.maps.ElevationStatus.OK) {
                if (results[0]) {
                    $('#result').text(results[0].elevation);
                } else {
                    alert("No results found");
                }
            } else {
                alert("Elevation service failed due to: " + status);
            }
        });
    });
});

我没有制作地图

也许我没有得到问题