谷歌地球Api-自己的图片

Google Earth Api- own pictures

本文关键字:自己的 Api- 谷歌地球      更新时间:2023-09-26

使用Google Earth API,我在特定坐标处创建了一些placemark。现在我还想将图像放置在与placemark相同的坐标上,以便向用户展示比默认标记图标更有意义的东西。有什么办法可以做到吗?

任何图片都可以作为placemark的图标。

要做到这一点,只需创建一个Placemark,然后将其样式设置为指向图像文件的自定义样式。

这样,您需要的图像将与Placemark位于相同的坐标。

下面的内容可以工作,显然您需要将http://yourserver/yourimage.png更改为指向图像:

// Create the placemark.
var placemark = ge.createPlacemark('');
placemark.setName("placemark");
// Define a custom icon.
var icon = ge.createIcon('');
icon.setHref('http://yourserver/yourimage.png');
var style = ge.createStyle(''); //create a new style
style.getIconStyle().setIcon(icon); //apply the icon to the style
placemark.setStyleSelector(style); //apply the style to the placemark
// Set the placemark's location.  
var point = ge.createPoint('');
point.setLatitude(12.345);
point.setLongitude(54.321);
placemark.setGeometry(point);
// Add the placemark to Earth.
ge.getFeatures().appendChild(placemark);

有关更多信息,请参阅API文档中的placemark部分。http://code.google.com/apis/earth/documentation/placemarks.html

你可以使用KmlPhotoOverlay

api参考:http://code.google.com/apis/earth/documentation/reference/interface_kml_photo_overlay-members.html

示例:http://earth-api-samples.googlecode.com/svn/trunk/examples/photo-overlay-viewer.html