2015-06-18 66 views
0

我在項目中使用Angular Google Maps。我沒有在tutoria中找到信息;如何使用地理位置和檢測當前用戶的位置。我如何做到這一點?如何在Angular JS谷歌地圖中使用地理定位?

我想:

$scope.getGeoLocation = function(){ 
       if (navigator.geolocation) { 
        navigator.geolocation.getCurrentPosition($scope.showPosition); 
       } else { 
        console.log("Geolocation is not supported by this browser."); 
       } 
      } 

      $scope.showPosition = function (position) { 
       $scope.map.bounds = { 
        northeast : position.coords.latitude, 
        southwest: position.coords.longitude 
       } 

       $scope.map.center = {latitude: position.coords.latitude, longitude: position.coords.longitude} 
       console.log(position.coords.longitude); 
      } 

,但我得到的錯誤:

Invalid map bounds for new value: {"northeast":40.409261699999995,"southwest":49.8670924}

+0

參見:GitHub的 - ngGeolocation:https://github.com/ninjatronic/ngGeolocation –

+0

更新的問題 – Caur

+0

誰能幫助我? – Caur

回答

0

入住條件,來源:
if !newValue?.northeast?.latitude? or !newValue?.northeast?.longitude? or !newValue?.southwest?.latitude? or !newValue?.southwest?.longitude? $log.error "Invalid map bounds for new value: #{JSON.stringify newValue}"