谷歌地图不会显示在 Phonegap iOS 应用程序中 [英] Google Map won't show in Phonegap iOS App

查看:33
本文介绍了谷歌地图不会显示在 Phonegap iOS 应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 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 = {缩放:12,中心:初始位置,mapTypeId: google.maps.MapTypeId.ROADMAP};var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);});<身体><div data-role="内容"><!--图片放在这里--><div class="img_shadow" style="padding:4px;"><div id="map_canvas" style="height:130px;"></div>

</div><!--/page -->

解决方案

PhoneGap 有一个用于外部 URL/主机的白名单系统.

来自维基:

<块引用>

此外,最新的代码具有新的白名单功能.如果你是引用外部主机,您必须将主机添加到PhoneGap.plist 在ExternalHosts"键下.通配符没问题.因此,如果您正在连接到http://phonegap.com",您必须添加phonegap.com"到列表(或使用通配符*.phonegap.com"也会匹配子域).

上面的代码片段中有一些外部主机:

  • maps.google.com
  • code.jquery.com

也许首先尝试将*"添加到 ExternalHosts 以确保这不是问题,然后在它工作后添加更多特定主机.

I have an PhoneGap iOS app and have this HTML that won't show the map in the app. I see the map perfectly in Safari or FF but not in the app. How can I get this to work?

    <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 has a whitelist system for external URLs/Hosts.

From the wiki:

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).

Your code snippet above has a few external hosts in it:

  • maps.google.com
  • code.jquery.com

Perhaps try adding "*" to ExternalHosts to start with to make sure that isn't the problem, then add more specific hosts once it's working.

这篇关于谷歌地图不会显示在 Phonegap iOS 应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
移动开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆