如何将Google地球功能集成到Flex中?

时间:2010-12-18 15:48:01

标签: javascript flex google-earth

我已成功使用ExternalInterface.call("javascriptMethodName")方法将Google地球与Flex集成,并在嵌入swf文件的html文件中编写javascript内容。它成功地运行并加载了Google Earth。

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script src="http://earth-api-samples.googlecode.com/svn/trunk/lib/kmldomwalk.js" type="text/javascript"> </script>
<script type="text/javascript" src="http://www.google.com/jsapi?key=I_Put_my_Key_Here"></script>
<script type="text/javascript">
google.load("earth", "1");
google.load("maps", "2.xx");  

var ge = null;
var geocoder;
var _position = [0,0,0,0];

function init() {
  geocoder = new GClientGeocoder();
  google.earth.createInstance('map3d', initCB, failureCB);
}

这是该html文件的片段,但是当我添加类似于html文件的内容时:

var directionsService = new google.maps.DirectionsService();

地球没有加载。任何人都可以建议如何克服这个问题。

谢谢!

1 个答案:

答案 0 :(得分:1)

你只能在加载后调用地图api,这取决于你拨打电话的位置。

除此之外,DirectionsService是V3 api的一部分,您正在加载版本2.

此外,google.maps.DirectionsService()是异步的,因为Google Maps API需要拨打外部服务器。因此,您需要传递一个回调方法,以便在请求完成时执行。此回调方法应处理结果。请注意,Directions服务可能会返回多个可能的行程,作为一系列单独的路线[]。

要使用V3中的路线,请创建一个DirectionsService类型的对象,并调用DirectionsService.route()以向Directions服务发起请求,并向其传递包含输入术语的DirectionsRequest对象文字以及在收到时执行的回调方法回应。

有关详细信息,请参阅文档:http://code.google.com/apis/maps/documentation/javascript/services.html#Directions