0
votes

Google has deprecated the methods getCurrentPosition() and watchPosition() from insecure origins. As I am developing an android application using ionic framework I cant use HTTPS. So I tried to use Cordova geolocation plugin but it is also not working. The code snippet of Cordova plugin is

$scope.getLocation = function () {
        alert('Get location Called')
        var posOptions = {
            timeout: 10000,
            enableHighAccuracy: false
        }
        $cordovaGeolocation
            .getCurrentPosition(posOptions)
            .then(function (position) {
                alert('getting current position')
                var lat = position.coords.latitude
                alert(lat)
                var long = position.coords.longitude
                alert(long)
            }, function (err) {
                console.log(err)
                alert(err.message)
            })
    }
<button class="button button-full button-assertive" ng-click="getLocation()">
            Get Location
        </button>

It gives me an error in console.log(err) like

PositionError {message: "Timeout expired", code: 3, PERMISSION_DENIED: 1, POSITION_UNAVAILABLE: 2, TIMEOUT: 3}

I only want to get the current position of the user. Is there any other way I could use to get the current latitude and longitude?

1
try remove plugin and then install again. - Atula
@Vaibhav If you are testing on device, could you reboot the device once? Also Go to Settings -> Location and security -> Use networks; and active it - Gandhi
@Atula I tried removing plugin and install it again but it is not working - Vaibhav Gole
have you tried @Gandhi's adivce. See this too stackoverflow.com/questions/20239846/… - Atula
@Atula I tried Gandhi's advice and its working now. Thank you very much for your help. - Vaibhav Gole

1 Answers

2
votes

If you are testing on device, you can reboot the device once. Also Go to Settings -> Location and security -> Use networks and active it. This should help.