GPS icon when using geolocation is not active


#1

I’m trying use two functions on my device Samsung Galaxy S2, Android 4.4.2.

    $scope.getCurrentLocationNavi = function() {         
        geolocationMain.getCurrentPosition().then(function(position){
        currentLongLat = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
            $scope.map.setCenter(currentLongLat);
            $scope.map.setZoom(17);
        }, function(err){
            alert(error(err));
        }, 
        {
             enableHighAccuracy: true,
             timeout: 1200000,
             maximumAge: 2000
        });              

    };
    $scope.getCurrentLocationCordova = function()
    {
        var watchOptions = {
          frequency : 1000,
          timeout : 3000,
          enableHighAccuracy: false // may cause errors if true
        };

        var watch = $cordovaGeolocation.watchPosition(watchOptions);

        watch.then(function(position) {
         currentLongLat = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
            $scope.map.setCenter(currentLongLat);
            $scope.map.setZoom(17);
          alert('assigning your new position');

        }, function(error) {
            alert('Error w/ watchPosition: ' + +JSON.stringify(error));
        });
    };

Neither are working, first function works only on my pc, but on device any of those. I also notice that they don’t try to call gps mechanism, because icon responsible for that is not showing. To comparison I open “Endomondo” and immidiately icon is showing and gps see my location.

Is Ionic appropriate for this type of app using maps?


#2

No one can help? Is this geolocation works on yours devices? If yes, gps icon is active when searching location?


#3

I can’t test my app now but I find next step to checkout.

  1. https://blog.nraboy.com/2014/10/use-crosswalk-ionic-framework-android-apps/

Maybe I should add some permisionss for device like:

 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
2. Maybe I should try crosswalk project on top of Ionic? I don't know if is compatible with the lastest Ionic version.

#4

Added permissions but seems to not solving my issue.

I also notice strange think. My index.html has:

<script src="lib/ngCordova/dist/ng-cordova.js" type="text/javascript" />

<script src="cordova.js"></script>

and code:

 if($window.cordova) { // window.cordova also checked
 }
 else
 { // here I am }

Strange :frowning:


#5

Ok, When I delete ngCordova, then I can enter into $window.cordova. Is this possible to use both ngCordova.js and cordova.js? I assume ‘cordova.js’ is fixed for ionic to enable working on device. So my question is, can I use ngCordova for my geolocation, and cordova.js to bootstrap app? Please can anybody say something?


#6

Yea its third day on this issue… and you know what? Cordova geolocation is not working on samsung galaxy II, III etc…

https://groups.google.com/forum/#!topic/phonegap/ESrHAjFHgFU

What the hell?


#7

Is there any other option to run geolocalisation without using “navigator.geolocation.”?


#8

is the geolocation permission in your config file ?


#9

In config.xml I added:

  <preference name="android-permission" value="ACCESS_FINE_LOCATION">

In …/platforms/android/AndroidManifest.xml I have at the bottom:

<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

#10

this is what i used when i was working on a geo app for work

https://cordova.apache.org/docs/en/3.0.0/cordova_geolocation_geolocation.md.html


#11

Thanks for your answers, really appreciate commitment.

This settings don’t fix this issue. I think it just not working and never been/will. Of course this is issue with Samsungs and android (4.1, 4.2, 4.4) and native browser. So I have to reject using Ionic (cordova) for that project. I will back when I have another one. But for geolocation purposes is not working, I can’t tell to the client, some phones will be working OK, some not. It just like slapping in the face… Use proper tool to proper problem -> so I go to “native”.


#12

did you try installing crosswalk ??

ionic browser add crosswalk

#13

It’s doable… i’m not using the watch geolocation plugin though. i’m using this: org.apache.cordova.geolocation


http://ngcordova.com/docs/plugins/geolocation/
Then the script i use to watch the location is:

var mainloop;

$scope.startloop = function(){
	if (angular.isDefined(mainloop) ) return;
	mainloop = $interval(function(){
		
		var options = {
			enableHighAccuracy: true,
			maximumAge: 0,
			timeout: 10000
		};
		
		$cordovaGeolocation.getCurrentPosition(options).then(function (pos) {
			latlong =  { 'lat' : pos.coords.latitude, 'long' : pos.coords.longitude };
			$rootScope.currentLocation = latlong;
		}, function(err) {});
		
	},30000);
};

$scope.stoploop = function(){
	if (angular.isDefined(mainloop)) {
		$interval.cancel(mainloop);
		mainloop = undefined;
	}
};

$scope.$on('$destroy', function() {
	// Make sure that the interval is destroyed too
	$scope.stoploop();
});

Hope this helps :slight_smile:


#14

Hi! This is incredible! It’s working, cmon :smile: So, this all issue with samsung galaxy is about first method invocation, its hanging. If we use time interval to do it again it’s start working. Huuuge thanks for yours help!


#15

No I didn’t yet. Issue is now solved by @sjerd.

But I will try update my app to crosswalk (but have to create new with cordova 3.6 - to the newest crosswalk version 12) because I read that this help older android devices to manage the same features. It’s like jquery in js I think.

Thanks for help!


#16

Use plugin sk.tamex.locationandsettings

my code: https://gist.github.com/brunoksato/5e7f9b2916289d1649a4

you can only call when you are sure that GPS is enabled, if not you will have an app that could not get over the location to restart the app


#17

Cannot call method ‘isGpsEnabled’ of undefined, i am getting this error for the plugin sk.tamex.locationandsettings

any help will be appriciated my code

var gpsEnabled = window.plugins.locationAndSettings;
$log.debug(‘gps enabled’+gpsEnabled)
gpsEnabled.isGpsEnabled(function(result) {

        });

#18

You don’t need to use interval. Instead you should initialize Geolocation in device ready event:

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {

}	

and it should work like a charm. Working example can be found here: Using Cordova Geoloacation API with Google Maps in Ionic Framework