应用程序不会显示在Android上

时间:2014-08-06 06:17:46

标签: javascript google-maps cordova google-api

我使用cordova创建了与地理位置Google地图相关联的应用。当我在浏览器中测试它时 - 没关系。其次,我在android上运行我的空Cordova应用程序 - 它也没关系。然后我将我的脚本粘贴到index.html中,我的应用程序不会显示在Android设备上。

这是身体的代码

<body onload="geoloc()">
<div id="divmap"></div>
    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript">
        app.initialize();
    </script>
</body>

有人知道为什么吗?非常感谢你

这是我的完整代码

  <html>
    <head>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
    <link rel="stylesheet" type="text/css" href="css/index.css" />
    <meta name="msapplication-tap-highlight" content="no" />
    <title>Hello World</title>

    <style>
        html, body, #divmap{
        height: 100%;
        margin: 0px;
        padding: 0px
    }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=weather">   </script>

    <script>
        var watchId = null;
        function geoloc() {
            if (navigator.geolocation) {
                // Get the user's current position
                var optn = {
                    enableHighAccuracy : true,
                    timeout : Infinity,
                    maximumAge : 0
                };
            watchId = navigator.geolocation.watchPosition(showPosition, showError, optn);
            } else {
                alert('Geolocation is not supported in your browser');
            }
            }

        function showPosition(position) {
            var googlePos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
            var mapOptions = {
                zoom : 12,
                center : googlePos,
                mapTypeId : google.maps.MapTypeId.ROADMAP
            };



            var mapObj = document.getElementById('divmap');
            var googleMap = new google.maps.Map(mapObj, mapOptions);    


            var markerOpt = {
                map : googleMap,
                position : googlePos,
                title : 'Hi , I am here',
                animation : google.maps.Animation.DROP
            };

            var googleMarker = new google.maps.Marker(markerOpt);

            var geocoder = new google.maps.Geocoder();
            geocoder.geocode({
                'latLng' : googlePos
            }, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                        if (results[1]) {
                            var popOpts = {
                                content : results[1].formatted_address,
                                position : googlePos
                            };
                            var popup = new google.maps.InfoWindow(popOpts);


                            /*google.maps.event.addListener(googleMap, 'center_changed', function(){
                                window.setTimeout(function(){
                                    googleMap.panTo(googleMarker.getPosition());
                                }, 2000);

                            });*/

                            google.maps.event.addListener(googleMarker, 'setTimeout', setTimeout (function() {
                                popup.open(googleMap, googleMarker)}, 200));

                        } else {
                            alert('No results found');
                        }
                } else {
                    alert('Geocoder failed due to: ' + status);
                }
            });

           var weatherLayer = new google.maps.weather.WeatherLayer({
              temperatureUnits: google.maps.weather.TemperatureUnit.Celsius
            });
            weatherLayer.setMap(googleMap);

            var cloudLayer = new google.maps.weather.CloudLayer();
            cloudLayer.setMap(googleMap);


        }

        function showError(error) {
            var err = document.getElementById('divmap');
            switch(error.code) {
                case error.PERMISSION_DENIED:
                    err.innerHTML = "User denied the request for Geolocation."
                    break;
                case error.POSITION_UNAVAILABLE:
                    err.innerHTML = "Location information is unavailable."
                    break;
                case error.TIMEOUT:
                    err.innerHTML = "The request to get user location timed out."
                    break;
                case error.UNKNOWN_ERROR:
                    err.innerHTML = "An unknown error occurred."
                    break;
            }
    }

   </script>
</head>
<body onload="geoloc()">
<div id="divmap"></div>
    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript">
        app.initialize();
    </script>
</body>
</html>

0 个答案:

没有答案