【问题标题】:Displaying a google map on iPhone simulator - Phonegap在 iPhone 模拟器上显示谷歌地图 - Phonegap
【发布时间】:2011-09-28 03:39:25
【问题描述】:

我正在运行 Mac OSX Lion 和 Xcode 4.1.1。我创建了一个新的 Phonegap 项目,并在 index.html 中添加了以下代码。

<!DOCTYPE html>
<html>
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />

    <script type="text/javascript" charset="utf-8" src="phonegap-1.0.0.js">
    </script>

    <!-- Tried setting sensor=true, didn't work too -->
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">
    </script>

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

    function display(position){
        var initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
        var myOptions = {
                zoom: 12,
                center: initialLocation,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
        var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
        }

        function error()
        {
            alert('Not working');
        }

        function init()
        {
            navigator.geolocation.getCurrentPosition(display,error);
        }
        </script>
    </head>
    <body onload="init()">
        <div id="map_canvas"></div>
    </body>
</html>

然而,该代码拒绝工作。我什至在Phonegap.plist 中启用了“EnableLocation”键。我没有收到任何警告说“Testapp 想知道你的位置,允许吗?”。我得到的只是控制台上的这个错误

navigator.geolocation.setError({ 'code': 1, 'message': 'Location Services Not Enabled' });

有人可以帮帮我吗?

【问题讨论】:

    标签: javascript xcode4 google-maps-api-3 cordova ios4


    【解决方案1】:

    我希望我知道要告诉你什么,但我希望这会有所帮助。我认为你的代码很好。我刚刚在 Snow Leopard 上的 Dreamweaver 的 iOS 4.3 模拟器上运行它,它运行良好。但是,我不得不进行一些调整,因为 DIV 完全崩溃了。地图在那里,但没有显示。

    只是为了证明给自己看,试着把它添加到你的 map_canvas div

    style="height: 400px"
    

    当我这样做时,我可以很好地看到地图。

    我不是 CSS 专家,所以我不知道如何让愚蠢的 div 扩展到地图的大小。也许你必须用 CSS 来做。高度 100% 不起作用。有时候 CSS 真的很厉害。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-20
      • 1970-01-01
      • 2010-11-09
      • 1970-01-01
      • 2012-12-10
      • 2011-07-04
      • 1970-01-01
      • 2012-06-02
      相关资源
      最近更新 更多