I’m having trouble using the $cordovaGeolocation. It works on the browser but when I build for android, I can’t make it work. These are my codes.
app.js
angular.module('ionic.sample', ['ionic','ngCordova'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
.controller('MapCtrl', function($scope, $cordovaGeolocation) {
function initialize() {
var posOptions = {timeout: 10000, enableHighAccuracy: false};
$cordovaGeolocation
.getCurrentPosition(posOptions)
.then(function (position) {
var lat = position.coords.latitude,
lng = position.coords.longitude,
myLoc = new google.maps.LatLng(lat, lng);
var mapOptions = {
streetViewControl:true,
zoom: 12,
center: myLoc,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var mapD = new google.maps.Map(document.getElementById('map'),
mapOptions);
var marker = new google.maps.Marker({
position: myLoc,
map: mapD,
title: 'Hello World!'
});
});
}
google.maps.event.addDomListener(window, 'load', initialize);
});