2016-03-27 71 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