I am trying to get to use ngCordova for getting my position and geocoding it to get a text formatted address. However it gives me no results as well as errors, which is why I am confused on this matter.
This is what I trying to do
function HomeCtrl($ionicPlatform, $cordovaGeolocation, myDriveApi) {
var vm = this;
vm.myLocation = "";
var geocoder = new google.maps.Geocoder();
var geoSettings = {
frequency: 1000,
timeout: 30000,
enableHighAccuracy: true // may cause errors if true
};
$cordovaGeolocation.getCurrentPosition(getPos, error, geoSettings);
function getPos(position) {
var LatLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
console.log(LatLng);
return showLocation(LatLng)
}
function error(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
function showLocation(LatLng) {
geocoder.geocode({'latLng': LatLng}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
vm.myLocation = results[0].formatted_address;
console.log(results);
}
})
};
I have found that I need to use $ionicPlatform, but I dont see it working with or without. Help me out on this matter
@soutlink Yeah the app is working fine, I see no errors on the browser, same for the app.
I have just recently changed to use $cordovaGeolocation to get my position on the map, and the same problem occurs, it is working in the browser but not on the device.
I am not sure if I can use native debugging for chrome, but might be a good idea to use logcat and see if there are any errors thrown at me
This is quite poor! I will have to change my implementation to use navigator, I been doing this for the past day and it is not fun.
But I noticed that it does give output after waiting for some time uisng ngCordova, only in one instance. In the my homeCtrl for reverse geocoding, but it doesn’t work on displaying markers on the google map at all.
But that also goes for navigator.geolocation it didn’t show any results in the device.
Is there any stable framework api for this that I can use or some way around it? I am not using crosswalk btw. But I got other plugings and dependencies on which might effect it
Regarding the Nexus not working but the browser does, you need to setup the Chrome USB debugging so that you can see the state of the objects.
By the looks of it you are not waiting for your platform to be ready. The first thing you are doing in your controller is trying to get a handle on your google.maps. This doesn’t work on my Nexus 5 because it takes a little longer to fire up the service.
I initially used the ionic.Platform.ready() function at the bottom of my controller but with the recent view caching improvements I have found that using this works better because you know the page is loaded and ready to use:
var geo = {};
$scope.$on('$ionicView.enter', function(event, data) {
geo = google.maps.Geocoder();
// carry on with other processing
})
hi my friend i have an issue with that , the geolocation ng cordovas plugin works in my browser but not in my device i already install the whitelist plugin and i put the security tag in my index.html but it still doesnt work. i dont know what to do google maps dont work, do i have to downgrade de cordova?
what would be your recomendation. thanks
thanks my friend , ive seen of all that suggeston and nothing… . i have
the same issue that u have even the same error code POSITION_UNAVAILABLE.
did you solve the problem?
Hey man; nope I was never able to fix it, however, if it helps, the issue does not happen when viewing your app on an iOS Device (through Ionic View or your app itself). Meaning, Geolocation doesn’t work on the iOS Simulator (for the both of us at least), but you can still test your Geolocation feature on your own iOS device without any issues!
Hopefully though, if it is issue with Ionic or Geolocation themselves not working in the iOS Simulator, it’s fixed in an upcoming release >.<.