地图未显示离子上的当前位置请求
Maps is not showing the current location request on ionic
在我的应用程序中,地图运行良好,我正在使用 android,我需要在状态栏中手动打开 'Local' 才能工作。我想在进入地图时显示请求。下面是我的代码,我正在使用 cordova 地理定位插件。
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);
latCS = new google.maps.LatLng(-27.465559, -48.378426);
var mapOptions = {
center: myLatLng,
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"),mapOptions);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: 'Your Pos'
});
var marker2 = new google.maps.Marker({
position: latCS,
map: map,
title: 'Your Dest'
});
var directionsDisplay = new google.maps.DirectionsRenderer();// also, constructor can get "DirectionsRendererOptions" object
directionsDisplay.setMap(map); // map should be already initialized.
var request = {
origin : myLatLng,
destination : latCS,
travelMode : google.maps.TravelMode.DRIVING
};
var directionsService = new google.maps.DirectionsService();
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
$scope.map = map;
});
}
ionic.Platform.ready(initialize)
});
我不清楚这个问题,但我假设您想要求用户直接从您的应用程序启用 GPS。
如果是这样,请看一下伟大的cordova-diagnostic-plugin. It has useful methods such as switchToSettings (Android, iOs) and switchToLocationSettings (Android, Windows Phone).
在调用这些方法之前,您可以向用户显示一个确认弹出窗口,要求他很好地启用Location/GPS(参见$ionicPopup)。
在我的应用程序中,地图运行良好,我正在使用 android,我需要在状态栏中手动打开 'Local' 才能工作。我想在进入地图时显示请求。下面是我的代码,我正在使用 cordova 地理定位插件。
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);
latCS = new google.maps.LatLng(-27.465559, -48.378426);
var mapOptions = {
center: myLatLng,
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"),mapOptions);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: 'Your Pos'
});
var marker2 = new google.maps.Marker({
position: latCS,
map: map,
title: 'Your Dest'
});
var directionsDisplay = new google.maps.DirectionsRenderer();// also, constructor can get "DirectionsRendererOptions" object
directionsDisplay.setMap(map); // map should be already initialized.
var request = {
origin : myLatLng,
destination : latCS,
travelMode : google.maps.TravelMode.DRIVING
};
var directionsService = new google.maps.DirectionsService();
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
$scope.map = map;
});
}
ionic.Platform.ready(initialize)
});
我不清楚这个问题,但我假设您想要求用户直接从您的应用程序启用 GPS。
如果是这样,请看一下伟大的cordova-diagnostic-plugin. It has useful methods such as switchToSettings (Android, iOs) and switchToLocationSettings (Android, Windows Phone).
在调用这些方法之前,您可以向用户显示一个确认弹出窗口,要求他很好地启用Location/GPS(参见$ionicPopup)。