2

I have created a PhoneGap app with jQuery Mobile. What I want to do is get mapkit in a tag.

The user should not have to click on any buttons to view the map. I want it to appear all the time in div.

Here is the entire example I use https://github.com/phonegap/phonegap-plugins/blob/master/iPhone/MapKitPlug/example/index.html

This works great but the user most click show map to show the map.

<script type="text/javascript" charset="utf-8">

                    function onBodyLoad() {
                        document.addEventListener("deviceready",onDeviceReady,false);
                    }

                    /* When this function is called, PhoneGap has been initialized and is ready to roll */
                    function onDeviceReady() {

                    }

                    var pins = [
                    { lat:58.389508,
                            lon:13.843042,
                            title:"place1",
                            subTitle:"placename",
                            pinColor:"purple", 
                            selected:true,
                            index:0
                        },
                                      ]

                     function showMap() {
                        // do your thing!
                        var mapOptions = {
                      height: 360,
                      diameter: 1000,
                      offsetTop: 25,
                      lat: pins[0].lat,
                      lon: pins[0].lon
                    };

                        window.plugins.mapKit.showMap();
                        window.plugins.mapKit.setMapData(mapOptions);
                        window.plugins.mapKit.addMapPins(pins);     
                    }

                </script>      

        </head>

        <body onload="onBodyLoad()">  


                    <button style="top:400px;position:absolute;" onclick="showMap()">Show</button>

This works great. But I want to do the same thing but with mapKit plugin for phonegap instead of google maps.

    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>

    <script src="http://code.jquery.com/jquery-1.6.2.min.js"></script>  
    <script type="text/javascript">

        $(document).ready(function(){
                    var initialLocation = new google.maps.LatLng(37.654,-77.980);
                        var myOptions = {
                                        zoom: 12,
                                        center: initialLocation,
                                        mapTypeId: google.maps.MapTypeId.ROADMAP
                        };
                        var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
            });
</script>   
</head> 
<body>
<div data-role="content">   
    <!--images go here -->
    <div class="img_shadow" style="padding:4px;">
                    <div id="map_canvas" style="height:130px;"></div>
    </div>
</div>      
</div><!-- /page -->

</body>
4

2 回答 2

0

如果您想在页面加载时自动显示地图。你可以这样做...

$(document).ready(function(){

   //Your map integration
   window.plugins.mapKit.showMap();

});
于 2013-01-16T10:20:20.370 回答
0

如果您希望地图自动加载,只需在页面加载时调用 showMap()。

定义 showMap 函数后:

function showMap() {
  // do your thing!
  var mapOptions = {
  height: 360,
  diameter: 1000,
  offsetTop: 25,
  lat: pins[0].lat,
  lon: pins[0].lon
 };

 window.plugins.mapKit.showMap();
 window.plugins.mapKit.setMapData(mapOptions);
 window.plugins.mapKit.addMapPins(pins);   
}
showMap(); // call it
于 2012-11-03T18:16:27.940 回答