1

phonegap でモバイル アプリを設計しています。これで、ユーザーの現在の場所を取得しようとしています。しかし、Andriod Emulator でマップを取得できません。私はこのコードを使用しました:

<!DOCTYPE HTML>

<html>

     <head>

<meta name="viewport" content="width=device-width; height=device-height; user-scalable=no" />

<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>PhoneGap Map</title>
<link rel="stylesheet" href="/master.css" type="text/css" media="screen" />
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>
<script type="text/javascript">

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

function onDeviceReady() {
    navigator.geolocation.getCurrentPosition(onSuccess, onError,{alert("error"),"enableHighAccuracy":true,"timeout":3000});

}

//GEOLOCATION
var onSuccess = function(position) {
    alert("Latitude: "  + position.coords.latitude   + "\n" +
          "Longitude:" + position.coords.longitude  + "\n");

    var myLat = position.coords.latitude;
    var myLong = position.coords.longitude;

    //MAP
    var mapOptions = {
        center: new google.maps.LatLng(myLat, myLong),
        zoom: 14,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    var map = new google.maps.Map(document.getElementById("map_canvas"),
                                  mapOptions);

};

// onError Callback receives a PositionError object
//
function onError(error) {
    alert("code: "    + error.code    + "\n" +
          "message: " + error.message + "\n");
}


     </script>

     </head>
     <body onload="onLoad()"> 
     <div>map</div>
     <div id="map_canvas" style="width:100px; height: 100px;" ></div>
     </body>
     </html>

どこが間違っているのかわかりません。誰か助けてください。

4

1 に答える 1

0

このコードを確認してください... cordova-1.8.1.js を ur cordova2.0.js に変更してください... 残りのソースはオンラインで参照してください。うまくいかない場合。それからあなたの phonegap 設定に問題があります。

<!DOCTYPE html>
<html>
    <head>
        <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
            <meta charset="utf-8">
                <title>Google Maps JavaScript API v3 Example: Info Window Simple</title>
                <link href="/maps/documentation/javascript/examples/default.css" rel="stylesheet">
                    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
                     <script type="text/javascript" charset ="utf-8" src="cordova-1.8.1.js"></script>
                    <script>
                        function initialize() {
                            var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
                            var mapOptions = {
                                zoom: 4,
                                center: myLatlng,
                                mapTypeId: google.maps.MapTypeId.ROADMAP
                            }

                            var map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);

                            var contentString = '<div id="content">'+
                            '<div id="siteNotice">'+
                            '</div>'+
                            '<h1 id="firstHeading" class="firstHeading">Uluru</h1>'+
                            '<div id="bodyContent">'+
                            '<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' +
                            'sandstone rock formation in the southern part of the '+
                            'Northern Territory, central Australia. It lies 335&#160;km (208&#160;mi) '+
                            'south west of the nearest large town, Alice Springs; 450&#160;km '+
                            '(280&#160;mi) by road. Kata Tjuta and Uluru are the two major '+
                            'features of the Uluru - Kata Tjuta National Park. Uluru is '+
                            'sacred to the Pitjantjatjara and Yankunytjatjara, the '+
                            'Aboriginal people of the area. It has many springs, waterholes, '+
                            'rock caves and ancient paintings. Uluru is listed as a World '+
                            'Heritage Site.</p>'+
                            '<p>Attribution: Uluru, <a href="http://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
                            'http://en.wikipedia.org/w/index.php?title=Uluru</a> '+
                            '(last visited June 22, 2009).</p>'+
                            '</div>'+
                            '</div>';

                            var infowindow = new google.maps.InfoWindow({
                                                                        content: contentString
                                                                        });

                            var marker = new google.maps.Marker({
                                                                position: myLatlng,
                                                                map: map,
                                                                title: 'Uluru (Ayers Rock)'
                                                                });
                            google.maps.event.addListener(marker, 'click', function() {
                                                          infowindow.open(map,marker);
                                                          });
                        }

                        </script>
                    </head>
    <body onload="initialize()">
        <div id="map_canvas"></div>
    </body>
</html>
于 2013-01-03T11:00:33.357 に答える