2012-05-03 2 views
0

이 자습서 http://www.mobiledevelopersolutions.com/home/start/twominutetutorials/tmt4part1을 따라했는데 문제가 하나 있습니다. Geolocation은 기본 Android 브라우저에서 작동하지 않습니다. Chrome, IE 및 Android 용 Chrome에서 작동합니다. 하지만 기본 Android 브라우저는 아닙니다.Google지도 v3 및 jQuery 모바일을 사용하는 Android의 Geolocation

나는 {enableHighAccuracy : true} 어딘가에 넣어 두어야한다고 생각했습니다. 알아낼 수 없습니다. 도움을

var mapdata = { destination: new google.maps.LatLng(51.3704888, 6.1723862) }; 

// Home page 
$('#page-home').live("pageinit", function() { 
    $('#map_square').gmap(
     { 'center' : mapdata.destination, 
      'zoom' : 12, 
      'mapTypeControl' : false, 
      'navigationControl' : false, 
      'streetViewControl' : false 
     }) 
     .bind('init', function(evt, map) { 
      $('#map_square').gmap('addMarker', 
       { 'position': map.getCenter(), 
        'animation' : google.maps.Animation.DROP 
});                                                    
     }); 
    $('#map_square').click(function() { 
     $.mobile.changePage($('#page-map'), {}); 
    }); 
}); 

function fadingMsg (locMsg) { 
    $("<div class='ui-overlay-shadow ui-body-e ui-corner-all fading-msg'>" + locMsg + "</div>") 
    .css({ "display": "block", "opacity": 0.9, "top": $(window).scrollTop() + 100 }) 
    .appendTo($.mobile.pageContainer) 
    .delay(2200) 
    .fadeOut(1000, function(){ 
     $(this).remove(); 
    }); 
} 

//Create the map then make 'displayDirections' request 
$('#page-map').live("pageinit", function() { 
    $('#map_canvas').gmap({'center' : mapdata.destination, 
     'mapTypeControl' : true, 
     'navigationControl' : true, 
     'navigationControlOptions' : {'position':google.maps.ControlPosition.LEFT_TOP} 
     }) 
    .bind('init', function() { 
     $('.refresh').trigger('tap');   
    }); 
}); 

$('#page-map').live("pageshow", function() { 
    $('#map_canvas').gmap('refresh'); 
}); 

// Request display of directions, requires jquery.ui.map.services.js 
var toggleval = true; // used for test case: static locations 
$('.refresh').live("tap", function() { 


      // START: Tracking location with device geolocation 
    if (navigator.geolocation) { 
     fadingMsg('Using device geolocation to get current position.'); 


     navigator.geolocation.getCurrentPosition ( 
      function(position) { 
       $('#map_canvas').gmap('displayDirections', 
       { 'origin' : new google.maps.LatLng(position.coords.latitude, position.coords.longitude), 
        'destination' : mapdata.destination, 'travelMode' : google.maps.DirectionsTravelMode.DRIVING}, 
       { 'panel' : document.getElementById('dir_panel')}, 
         function (result, status) { 
          if (status === 'OK') { 
           var center = result.routes[0].bounds.getCenter(); 
           $('#map_canvas').gmap('option', 'center', center); 
           $('#map_canvas').gmap('refresh') 
          } else { 
           alert('Unable to get route'); 
          } 
         } 
        );   
       }, 
       function(){ 
        alert('Unable to get location'); 
        $.mobile.changePage($('#page-home'), { }); 

       }); 
      } else { 
       alert('Unable to get location.'); 
      }   
    // END: Tracking location with device geolocation 
    $(this).removeClass($.mobile.activeBtnClass); 
    return false; 
}); 


// Go to map page to see instruction detail (zoom) on map page 
$('#dir_panel').live("tap", function() { 
    $.mobile.changePage($('#page-map'), {}); 
}); 

// Briefly show hint on using instruction tap/zoom 
$('#page-dir').live("pageshow", function() { 
    fadingMsg("Tap any instruction<br/>to see details on map"); 
}); 

들으 :

이 코드입니다!

답변

3

전화를해야 할 수도 있습니다.

navigator.geolocation.getCurrentPosition(successCallback, 
             errorCallback, 
             {maximumAge:Infinity, timeout:0, enableHighAccuracy: true }); 

여기서 maximumAge 및 timeout 값을 변경할 수 있지만 여기에서 enableHighAccuracy를 설정합니다. getcurrentposition 메소드에서 세 번째 매개 변수로 지정하십시오.

편집 : 당신이 위치 정보를 사용하려면 때문에

navigator.geolocation.getCurrentPosition ( 
     function(position) { 
      $('#map_canvas').gmap('displayDirections', 
      { 'origin' : new google.maps.LatLng(position.coords.latitude, position.coords.longitude), 
       'destination' : mapdata.destination, 'travelMode' : google.maps.DirectionsTravelMode.DRIVING}, 
      { 'panel' : document.getElementById('dir_panel')}, 
        function (result, status) { 
         if (status === 'OK') { 
          var center = result.routes[0].bounds.getCenter(); 
          $('#map_canvas').gmap('option', 'center', center); 
          $('#map_canvas').gmap('refresh') 
         } else { 
          alert('Unable to get route'); 
         } 
        } 
       );   
      }, 
      function(){ 
       alert('Unable to get location'); 
       $.mobile.changePage($('#page-home'), { }); 

      }, 
    { enableHighAccuracy: true }); 
+0

다른 장소에 넣으려고하지만 작동하지 않습니다. 내 코드에서 정확한 위치를 지적 해 주시겠습니까? 고맙습니다! – Maxcim

+0

@Maxcim 지금 사용해보십시오. –

+0

내가 그 장소에 올려 놓으면 작동하지 않지만 IE와 Chrome에서도 작동하지 않습니다. – Maxcim

-1

, 당신은 참으로 센서를 설정? false로 설정하면 작동하지 않기 때문입니다.

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true"></script> 
+0

센서 매개 변수는 어떤 식 으로든 결과에 영향을 미치지 않습니다. Google에 대한 참고 사항 일뿐입니다. http://stackoverflow.com/questions/8616764/what-is-the-sensor-parameter-in-google-places-api-good-for –