我有一个PhoneGap iOS应用程序,并且这个
HTML将不会显示应用程序中的地图.我在Safari或FF中完美地看到了地图,但在应用程序中却没有.我该如何让这个工作?
<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>
解决方法
PhoneGap具有用于外部URL /主机的白名单系统.
从维基:
Also,the latest code has the new white-list feature. If you are
referencing external hosts,you will have to add the host in
PhoneGap.plist under the “ExternalHosts” key. Wildcards are ok. So if
you are connecting to “http://phonegap.com”,you have to add
“phonegap.com” to the list (or use the wildcard “*.phonegap.com” which
will match subdomains as well).
您的上面的代码片段有几个外部主机:
> maps.google.com
> code.jquery.com