Anyone got ionic ios geolocation working app ? ios 8?

anyone success to get the geolocation in ios 8 ionic app ?? am keep getting time out error

can anyone confirm this :

ionic start mytestapp maps
ionic platform add ios
ionic build ios
then run from Xcode or in emulator

dose the geolocation work ??

did you set the permissions in the plist?

<key>NSLocationAlwaysUsageDescription</key>
<string>My app requires constant access to your location, even when the screen is off.</string>


<key>NSLocationWhenInUseUsageDescription</key>
<string>My app requires access to your location when the screen is on and the app is displayed.</string>

yes both from the Xcode

I am having problems initiating geolocation in ios. When the app starts there is no geolocation. I set timeout to 5000, but no luck. However if I login (or logout) of my application, suddenly geolocation starts working. The accounts tab that handles login is in a different tab and forces a browser refresh. Failed to do the same on the geolocation tab. I have reported the same here as well. :frowning:

Without setting permission in the plist, geolocation works once I am logged in. :unamused:

All this works well on Android.

Hey Doc,

This is how I just fixed it.

Add this to your config.xml per (https://cordova.apache.org/docs/en/3.0.0/cordova_geolocation_geolocation.md.html)

image


remove the plugin and install from git per http://stackoverflow.com/questions/24392943/cordova-geolocation-issues-in-ios-8-beta-2

ionic plugin rm cordova-plugin-geolocation
ionic plugin add GitHub - apache/cordova-plugin-geolocation: Apache Cordova Geolocation Plugin

Make sure you set up your google api key and enable the services.

Then, you’ve got to add an event listener or you’ll get a nasty warning as the app opens.

document.addEventListener(“deviceready”, onDeviceReady, false);
function onDeviceReady() {
console.log(“navigator.geolocation works well”);
}

Last note. If you want to do testing in the browser you’ll need to check if your using a device or the browser or you’ll get nothing but a white screen.

Here’s it all together:

//Browser
if(!(ionic.Platform.isIOS() || ionic.Platform.isAndroid())) {

        var options = {timeout: 10000, enableHighAccuracy: true};
        $cordovaGeolocation.getCurrentPosition(options).then(function (position) {
            console.log(position);
            var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
            var mapOptions = {
                center: latLng,
                zoom: 15,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            $scope.map = new google.maps.Map(document.getElementById("map"), mapOptions);
            //Wait until the map is loaded
            google.maps.event.addListenerOnce($scope.map, 'idle', function () {
                var marker = new google.maps.Marker({
                    map: $scope.map,
                    animation: google.maps.Animation.DROP,
                    position: latLng
                });
                var infoWindow = new google.maps.InfoWindow({
                    content: "Here I am!"
                });
                google.maps.event.addListener(marker, 'click', function () {
                    infoWindow.open($scope.map, marker);
                });
            });
        })
}
//Native
else {
    document.addEventListener("deviceready", onDeviceReady, false);
    function onDeviceReady() {
        console.log("navigator.geolocation works well");
        var options = {timeout: 10000, enableHighAccuracy: true};
        $cordovaGeolocation.getCurrentPosition(options).then(function (position) {
            console.log(position);
            var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
            var mapOptions = {
                center: latLng,
                zoom: 15,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            $scope.map = new google.maps.Map(document.getElementById("map"), mapOptions);
            //Wait until the map is loaded
            google.maps.event.addListenerOnce($scope.map, 'idle', function () {
                var marker = new google.maps.Marker({
                    map: $scope.map,
                    animation: google.maps.Animation.DROP,
                    position: latLng
                });
                var infoWindow = new google.maps.InfoWindow({
                    content: "Here I am!"
                });
                google.maps.event.addListener(marker, 'click', function () {
                    infoWindow.open($scope.map, marker);
                });
            });
        }, function (error) {
            console.log("Could not get location");
            console.log(error);
        });
    }
}

Hope this helps.

Note: I just took a look into this further and found that ionic.Platform.ready() might be a better way to check than onDeviceReady(). You should be able to get rid of the check if it’s a browser or not.

there is something up with this plugin. It gives me this error whenever i try to add it

Error happened [TypeError: Object.keys called on non-object]
TypeError: Object.keys called on non-object
at Function.keys (native)
at Object.getPluginFromFetchJsonByLocator (/usr/local/lib/node_modules/ionic/node_modules/ionic-app-lib/lib/state.js:744:26)
at Object.savePlugin (/usr/local/lib/node_modules/ionic/node_modules/ionic-app-lib/lib/state.js:673:36)
at /usr/local/lib/node_modules/ionic/lib/ionic/cordova.js:95:22
at _fulfilled (/usr/local/lib/node_modules/ionic/node_modules/q/q.js:787:54)
at self.promiseDispatch.done (/usr/local/lib/node_modules/ionic/node_modules/q/q.js:816:30)
at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/ionic/node_modules/q/q.js:749:13)
at /usr/local/lib/node_modules/ionic/node_modules/q/q.js:557:44
at flush (/usr/local/lib/node_modules/ionic/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:355:11)