0

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

<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();

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

谢谢 !!

4

1 回答 1

1

您只能在加载地图 api 后对其进行调用,因此这取决于您调用的位置。

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

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

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

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

于 2011-02-25T17:43:13.873 回答