Geolocation.getCurrentPosition not working in ANDROID device


#1

geolocation.getCurrentPosition not working in ANDROID device, but when using in browser it’s working fine

What else i have to do…

This is my controller
.controller(‘MapController’, function($scope, $ionicLoading,$http,$ionicPopup) {

google.maps.event.addDomListener(window, 'load', function() {
    var myLatlng = new google.maps.LatLng(37.3000, -120.4833);

    var mapOptions = {
        center: myLatlng,
        zoom: 16,
        
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    var map = new google.maps.Map(document.getElementById("map"), mapOptions);

    navigator.geolocation.getCurrentPosition(function(pos) {
        map.setCenter(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));
        var myLocation = new google.maps.Marker({
            position: new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude),
            map: map,
            title: "My Location"
        });

       var lat_long = pos.coords.latitude+","+pos.coords.longitude;
       var link = "https://api.forecast.io/forecast/[MY API KEY]/"+lat_long;

        $http.get(link, {}).then(function (res){
           //console.log(res.data.currently.temperature);
          var farenheit_temp = res.data.currently.temperature;
          var celcius_temp = (farenheit_temp - 30) / 2;
           var alertPopup = $ionicPopup.alert({
                  title: 'Details',
                  template: "<p>Temperature:- "+celcius_temp.toFixed(2)+" c<br/>"+res.data.currently.summary+"<br/>Humidity:- "+res.data.currently.humidity+"<br>Wind Speed:- "+res.data.currently.windSpeed+"</p>",
            });
       });

    },function(){},{maximumAge:60000, timeout:2000, enableHighAccuracy:true});

    $scope.map = map;
});

})


#2

Not all android support navigator, so I use to this purpose plugin https://github.com/louisbl/cordova-locationservices. Because it allow me get user’s position from google play services.


#3

will it work for IOS too


#4

In iOS you should use navigator, becuase it work good in all iPhone which I tested ex. iPhone 4 and 6 and probable iPhone 5. On iPad 2 work good, too.


#5

Does it work with android 6? It tried but no success.