4

I have set a google maps (api v3) on div. Then I want to retrieve the map via the div.

Doing something like

theMap = $('.myDiv').theGoogleMap;

I can't find this simple info. Thank you for your help.

4

3 に答える 3

2

それはできません。グローバル変数を宣言して、その変数にマップ オブジェクトへの参照を保存できます。Google ドキュメントのサンプルを見てください。

      var map;
      function initialize() {
        var myOptions = {
          zoom: 8,
          center: new google.maps.LatLng(-34.397, 150.644),
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(document.getElementById('map_canvas'),
            myOptions);
      }

      google.maps.event.addDomListener(window, 'load', initialize);

また、ここにJavascriptチュートリアルがあります:

https://developer.mozilla.org/en/JavaScript/Guide

于 2012-05-30T15:09:41.717 に答える
0

API はその方向には機能しません。オブジェクトを作成するときは、JavaScript でオブジェクトへの参照を保持する必要があります。DOM 参照からマップ オブジェクトを検索することはできません。

于 2012-05-30T15:10:25.450 に答える