2011-12-23 61 views
1

我正在使用'jquery-ui-map'爲一個android應用程序。我的模擬器是Google API 13級版本3.2。我的Javascript代碼是:Android模擬器 - 如何獲取地理位置?

$('#gps_map').live("pageshow", function() { 
$('#map_canvas_2').gmap('refresh'); 
$('#map_canvas_2').gmap('getCurrentPosition', function(position, status) { 
    if (status === 'OK') { 
     var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude) 
     $('#map_canvas_2').gmap('get', 'map').panTo(latlng); 
     $('#map_canvas_2').gmap('search', { 'location': latlng }, function(results, status) { 
      if (status === 'OK') { 
       $('#from').val(results[0].formatted_address); 
      } 
     }); 
    } else { 
     alert('Unable to get current position'); 
    } 
});}); 

此代碼總是無法獲取位置。我無法在模擬器中看到GPS圖標。我嘗試設置所有可能的權限,嘗試使用地理修復方法設置latlong座標,但沒有任何效果。有任何地理位置可以在Android上工作的方式嗎?

+0

好吧忘了'jquery-ui-map',你能指點我在模擬器中正確處理的GPS位置嗎? – Ved 2011-12-25 06:25:09

回答

0

終於找到了答案。

$('#map_canvas').gmap('getCurrentPosition', function(pos, status) { 
     if (status === "OK") { 
      var latLng = new google.maps.LatLng(pos.coords.latitude,pos.coords.longitude); 
      $('#map_canvas').gmap('option', 'center', latLng); 
     } else { 
      // error msg 
     } 
    }, { timeout: 10000, enableHighAccuracy: true}); 

在選項中添加更長的timout(如上所示)可修復問題。該示例顯示了超時時間:10秒。

相關問題