2011-09-30 23 views
6

Kullanıcının konumunu coğrafi konum kitaplığını kullanarak gösterecek bir komut dosyası oluşturdum ve her şey düzgün çalışıyor. PhoneGap kullanarak bu HTML 5 komut dosyasını verdim ve Ayarlar-> Konum Hizmetleri Uygulamam'ın Açık olarak ayarlandığını görebiliyorum. Bu yüzden her seferinde Uygulamamı çalıştırdığımı varsaydım. Normal soruyu alamayacağım ".... Mevcut konumunuzu kullanmak ister misiniz?" Seçeneklere İzin Verme veya Tamam.HTML 5 coğrafi konum telefon kullanarakGap

Kullanıcıları, Uygulamamı her açtıklarında İzin Ver'i tıklatmak istemiyorum. Uygulamanın Hizmetler -> Konum Ayarları'ndan bu ayarı kullanmamasının bir nedeni var mı? Aşağıda basit script: Aygıt için beklemelisiniz Her yere baktım ve buldum

<!DOCTYPE html> 
<html> 
    <head> 
     <meta name="apple-mobile-web-app-capable" content="yes" /> 

     <meta name="apple-mobile-web-app-status-bar-style" content="black" /> 
     <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> 

     <link rel="apple-touch-icon-precomposed" href="custom_icon_precomposed.png"/> 
     <link rel="apple-touch-startup-image" href="apple-touch-icon-precomposed.png"> 
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript"></script> 
      <script> 

       jQuery(window).ready(function(){ 
            jQuery("#btnInit").click(initiate_watchlocation); 
            jQuery("#btnStop").click(stop_watchlocation); 
            }); 

       var watchProcess = null; 

       function initiate_watchlocation() { 
        if (watchProcess == null) { 
         watchProcess = navigator.geolocation.watchPosition(handle_geolocation_query, handle_errors, {enableHighAccuracy:true}); 
        } 
       } 

       function stop_watchlocation() { 
        if (watchProcess != null) 
        { 
         navigator.geolocation.clearWatch(watchProcess); 
         watchProcess = null; 
        } 
       } 

       function handle_errors(error) 
       { 
        switch(error.code) 
        { 
         case error.PERMISSION_DENIED: alert("user did not share geolocation data"); 
         break; 

         case error.POSITION_UNAVAILABLE: alert("could not detect current position"); 
         break; 

         case error.TIMEOUT: alert("retrieving position timedout"); 
         break; 

         default: alert("unknown error"); 
         break; 
        } 
       } 

       function handle_geolocation_query(position) { 
        var text = "Latitude: " + position.coords.latitude + "<br/>" + 
        "Longitude: " + position.coords.longitude + "<br/>" + 
        "Accuracy: " + position.coords.accuracy + "m<br/>" + 
        "Time: " + new Date(position.timestamp); 
        jQuery("#info").html(text); 

        var image_url = "http://maps.google.com/maps/api/staticmap?sensor=false&center=" + position.coords.latitude + ',' + position.coords.longitude + 
        "&zoom=14&size=300x400&markers=color:blue|label:S|" + position.coords.latitude + ',' + position.coords.longitude; 

        jQuery("#map").remove(); 
        jQuery(document.body).append( 
               jQuery(document.createElement("img")).attr("src", image_url).attr('id','map') 
               ); 
       } 
       </script> 
      </head> 
    <body> 
     <div> 
      <button id="btnInit" >Monitor my location</button> 

      <button id="btnStop" >Stop monitoring</button> 
     </div> 
     <div id="info"></div> 
    </body> 
</html> 

cevap

2

Tamam o zaman hazır olması doğal işlevleri kullanmak için içerde senin window.ready jquery aramak için. Bunu bir noob olarak ilan edeceğimi düşündüm, aradığım cevabı bulmak için tüf idi.

 // Wait for PhoneGap to load 
     // 
     document.addEventListener("deviceready", onDeviceReady, false); 

     // PhoneGap is ready 
     // 
     function onDeviceReady() { 
      jQuery(window).ready(function(){ 
       jQuery("#btnInit").click(initiate_watchlocation); 
       jQuery("#btnStop").click(stop_watchlocation); 
      }); 

     } 
İlgili konular