首先,我要感谢你们的回答。
其次,我创建了一个包含Google Earth插件的网站,我使用KML字符串来显示两个坐标。我想看经度-122.084075,纬度37.4220033612141。 当我加载我的网站时,我没有看到任何变化。
我的html代码+ kml字符串:
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"> </script>
<script type="text/javascript">
var ge;
google.load("earth", "1", {"other_params":"sensor=false"});
function init()
{
google.earth.createInstance('map3d', initCB, failureCB);
}
function initCB(instance)
{
ge = instance;
ge.getWindow().setVisibility(true);
addKmlFromString(
'<?xml version="1.0" encoding="UTF-8"?>' +
'<kml xmlns="http://earth.google.com/kml/2.0">' +
'<Document>' +
'<Placemark>' +
' <name>Floating placemark</name>' +
' <visibility>1</visibility>' +
' <description>Floats a defined distance above the ground.</description>' +
' <LookAt>' +
' <longitude>-122.084075</longitude>' +
' <latitude>37.4220033612141</latitude>' +
' <altitude>45</altitude>' +
' <heading>0</heading>' +
' <tilt>90</tilt>' +
' <range>100</range>' +
' <altitudeMode>relativeToGround</altitudeMode>' +
' </LookAt>' +
' <Style>' +
' <IconStyle>' +
' <Icon>' +
' <href>https://cdn1.iconfinder.com/data/icons/future/512/drones_watching-64.png</href> ' +
' </Icon>' +
' </IconStyle>' +
' </Style>' +
' <Point>' +
' <altitudeMode>relativeToGround</altitudeMode>' +
' <coordinates>-122.0822035425683,37.42228990140251,50</coordinates>' +
' </Point>' +
'</Placemark>' +
' <Placemark>' +
' <name>Flight Line</name>' +
' <visibility>1</visibility>' +
' <description>Black line (10 pixels wide), height tracks terrain</description>' +
' <styleUrl>#thickBlackLine</styleUrl>' +
' <LineString>' +
' <tessellate>1</tessellate>' +
' <altitudeMode>relativeToGround</altitudeMode>' +
' <coordinates>' +
' -122.0822035425683,37.42228990140251,0' +
' -122,37.8,0' +
' </coordinates>' +
' </LineString>' +
' </Placemark>' +
'<Placemark><name>From</name><Point><coordinates>-122.0822035425683,37.42228990140251,0</coordinates></Point></Placemark>' +
'<Placemark><name>To</name><Point><coordinates>-122,37.8,0</coordinates></Point></Placemark>' +
'</Document>' +
'</kml>'
);
}
function addKmlFromString(kmlString)
{
var kmlObject = ge.parseKml(kmlString);
ge.getFeatures().appendChild(kmlObject);
}
function failureCB(errorCode)
{
}
google.setOnLoadCallback(init);
</script>
</head>
<body>
<div id="map3d" style="height: 300px; width: 400px;"></div>
</body>
</html>
请指导我。我究竟做错了什么? 非常感谢!
答案 0 :(得分:0)
我在这里找到了答案: https://developers.google.com/earth/documentation/camera_control#flytospeed
缩放相机
放大和缩小由LookAt的range属性和Camera的高度属性控制。
请注意,更改LookAt的高度属性会更改正在查看的点的高度。由于观察者范围与此点相关,因此观察者的高度也会发生变化。
注视:
// Get the current view.
var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
// Zoom out to twice the current range.
lookAt.setRange(lookAt.getRange() * 2.0);
// Update the view in Google Earth.
ge.getView().setAbstractView(lookAt);
答案 1 :(得分:0)
请参阅此链接https://developers.google.com/earth/documentation/kml
你错过了一行ge.getView().setAbstractView(kmlObject.getAbstractView());
在ge.getFeatures().appendChild(kmlObject);
之后加上这一行