2016-03-27 72 views
0

當前的位置請求在我的應用程序地圖工作正常,我使用android和我需要在狀態欄上手動打開'本地'工作。我想在地圖中輸入時顯示請求。貝婁是我的代碼,我正在使用cordova geolocation插件。地圖不顯示離子

angular.module('myApp.controllers', ['ionic']) 
 

 

 
.controller('NavCtrl', function($scope, $ionicLoading, $compile, $ionicModal, $timeout) { 
 
    var myLatLng; 
 
    var latCS; 
 

 
    
 
    function initialize() { 
 

 
    
 
    navigator.geolocation.getCurrentPosition(function(position) { 
 
     myLatLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); 
 
\t \t latCS = new google.maps.LatLng(-27.465559, -48.378426); 
 
\t \t 
 
    
 
     var mapOptions = { 
 
      center: myLatLng, 
 
      zoom: 10, 
 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
 
     }; 
 
     var map = new google.maps.Map(document.getElementById("map"),mapOptions); 
 
\t \t 
 

 
     var marker = new google.maps.Marker({ 
 
      position: myLatLng, 
 
      map: map, 
 
      title: 'Your Pos' 
 
     }); 
 
\t \t 
 
\t \t var marker2 = new google.maps.Marker({ 
 
      position: latCS, 
 
      map: map, 
 
      title: 'Your Dest' 
 
     }); 
 
\t \t 
 

 
\t \t var directionsDisplay = new google.maps.DirectionsRenderer();// also, constructor can get "DirectionsRendererOptions" object 
 
\t \t directionsDisplay.setMap(map); // map should be already initialized. 
 

 
\t \t var request = { 
 
\t \t \t origin : myLatLng, 
 
\t \t \t destination : latCS, 
 
\t \t \t travelMode : google.maps.TravelMode.DRIVING 
 
\t \t }; 
 
\t \t var directionsService = new google.maps.DirectionsService(); 
 
\t \t directionsService.route(request, function(response, status) { 
 
\t \t \t if (status == google.maps.DirectionsStatus.OK) { 
 
\t \t \t \t directionsDisplay.setDirections(response); 
 
\t \t \t } 
 
\t \t }); 
 
     $scope.map = map; 
 
    }); 
 
    } 
 
    
 

 
    ionic.Platform.ready(initialize) 
 
    
 
});

+0

任何人都可以幫助我嗎? – Sobucki

回答

0

的問題是,我也不清楚,但我以爲你要問用戶啓用了GPS,直接從您的應用程序。

如果是這樣,請看看偉大的cordova-diagnostic-plugin。它有很多有用的方法,如switchToSettings(Android,iOs)和switchToLocationSettings(Android,Windows Phone)。

在調用這些方法之前,您可能會向用戶顯示一個確認彈出框,要求他很好地以啓用位置/ GPS(請參閱$ionicPopup)。

+0

我解決了使用cordova-diagnostic-plugin,謝謝你。 – Sobucki

+0

不客氣!如果你喜歡它,不要忘了在GitHub上登錄這個項目。我個人認爲它是科爾多瓦項目中最有用的插件之一:)(項目中沒有興趣,只是我的愚見)! – VinceOPS