Javascript 如何在google earth插件中通过文本框的内容设置摄像头?

Javascript 如何在google earth插件中通过文本框的内容设置摄像头?,javascript,google-earth,google-earth-plugin,Javascript,Google Earth,Google Earth Plugin,目前我正在使用Google Earth插件代码。此时,我正试图根据某些文本框的内容移动相机。这是我目前拥有的代码 var ge; google.load("earth", "1"); function init() { google.earth.createInstance('map3d', initCallback, failureCallback); //create boxes addSampleUIHtml( '<input id="Altitude" type

目前我正在使用Google Earth插件代码。此时,我正试图根据某些文本框的内容移动相机。这是我目前拥有的代码

var ge;

google.load("earth", "1");

function init() {
  google.earth.createInstance('map3d', initCallback, failureCallback);
//create boxes
  addSampleUIHtml(
    '<input id="Altitude" type="text" value="500000"/>');
  addSampleUIHtml(
    '<input id="Longitude" type="text" value="2"/>');
  addSampleUIHtml(
    '<input id="Latitude" type="text" value="42"/>');  
  addSampleUIHtml(
    '<input id="Heading" type="text" value="0"/>');  
  addSampleUIHtml(
    '<input id="Tilt" type="text" value="0"/>');
  addSampleUIHtml(
    '<input id="Roll" type="text" value="0"/>');    
  addSampleButton('Move the camera', buttonClick);
}

function initCallback(instance) {
  ge = instance;
  ge.getWindow().setVisibility(true);

  // just for debugging purposes
  document.getElementById('installed-plugin-version').innerHTML =
    ge.getPluginVersion().toString();
}

function failureCallback(errorCode) {
}

function buttonClick() {

  var AltitudeInBox=document.getElementById('Altitude').value

  var CameraAt= ge.getView().copyAsCamera(ge.ALTITUDE_ABSOLUTE);
  CameraAt.set   (  41.383, // latitude +-90
                               2.183 , // longitude +-180
                               AltitudeInBox, // altitude (m)
                               ge.ALTITUDE_ABSOLUTE, // reference altitude mode
                               0,  //heading Direction (that is, North, South, East, West), in degrees. Default=0 (North). Values range from 0 to 360 degrees
                               0, //Tilt 0 to 360 degrees.
                               0 //Rotation, in degrees around the Z axis. -180 to +180 degrees.

  ge.getView().setAbstractView(CameraAt)
}
var-ge;
谷歌加载(“地球”,“1”);
函数init(){
createInstance('map3d',initCallback,failureCallback);
//创建框
addSampleUIHtml(
'');
addSampleUIHtml(
'');
addSampleUIHtml(
'');  
addSampleUIHtml(
'');  
addSampleUIHtml(
'');
addSampleUIHtml(
'');    
addSampleButton(“移动相机”,按钮单击);
}
函数initCallback(实例){
ge=实例;
ge.getWindow().setVisibility(true);
//只是为了调试的目的
document.getElementById('installed-plugin-version').innerHTML=
ge.getPluginVersion().toString();
}
函数故障回调(错误代码){
}
函数按钮单击(){
var AltitudeInBox=document.getElementById('Altitude')。值
var CameraAt=ge.getView().copyAsCamera(ge.ALTITUDE\u绝对值);
CameraAt.set(41.383,//纬度+-90
2.183,//经度+-180
AltitudeInBox,//高度(m)
ge.ALTITUDE\u ABSOLUTE,//参考高度模式
0,//航向方向(即北、南、东、西),单位为度。默认值为0(北)。值的范围为0到360度
0,//将0倾斜到360度。
0//绕Z轴旋转,以度为单位,-180到+180度。
ge.getView().setAbstractView(CameraAt)
}
当我将变量AltitudeInBox定义为框高度的内容时,valor传递给它。我使用了alert函数(alert(AltitudeInBox);),但是当我将变量AltitudeInBox作为函数CameraAt.set的参数传递时,我没有得到任何结果。 我怀疑变量AltitudeInBox被指定为图表而不是数字,但不知道如何更改它。
提前谢谢。

我找到了解决方案。这是初学者的错误。以下声明:

 var AltitudeInBox=document.getElementById('Altitude').value
将高度框的内容指定为图表变量,但以下代码需要一个数字

   CameraAt.set   (  41.383, // latitude +-90
                               2.183 , // longitude +-180
                               AltitudeInBox, // altitude (m)
                               ge.ALTITUDE_ABSOLUTE, // reference altitude mode
                               0,  //heading Direction (that is, North, South, East,West), in degrees. Default=0 (North). Values range from 0 to 360 degrees
                               0, //Tilt 0 to 360 degrees.
                               0 //Rotation, in degrees around the Z axis. -180 to +180degrees.
解决方案是使用parseFloat()或parseInt(),如下所示

   CameraAt.set   (  parseFloat(document.getElementById('Latitude').value),
                     parseFloat(document.getElementById('Longitude').value) ,
                     parseFloat(document.getElementById('Altitude').value), 
                     ge.ALTITUDE_ABSOLUTE, //altitude mode
                     parseFloat(document.getElementById('Heading').value),
                     parseFloat(document.getElementById('Tilt').value),
                     parseFloat(document.getElementById('Roll').value)    )