Google Places Autocomplete does not work on mobile
It's not possible to select an google places autocomplete entry on mobile. I'm using the ngAutocomplete directive.
It does work on desktop:

And this happens on mobile:

Here an example plunker: http://plnkr.co/edit/UNQCivHSRMEofAP944RJ?p=preview
You can test this behavior on mobile and also with the chrome dev tools device emulation (Version 37.0.2062.3 dev).
Here a corresponding forum thread: http://forum.ionicframework.com/t/google-maps-address-autocomplete-inside-slide-box/5278/8
Hey @ch000, so data-tap-disable would be great here, but since the container used to make the autocomplete is being generated and we have no controller over it, we have to use a directive to work around it.
So try this
.directive('disableTap', function($timeout) {
return {
link: function() {
$timeout(function() {
document.querySelector('.pac-container').setAttribute('data-tap-disabled', 'true')
},500);
}
};
});
http://plnkr.co/edit/SjSDzb70NcXImWk9n5lX?p=preview
It works now in plunker, just make sure to use it on the body tag. Going to close this for now, but reopen it if the issue is not resolved.
The issue still stands, when you test the plunker in emulation mode you will see what I am talking about.
Yes, the issue still stands
+1 still an issue
anyone found any solution for this problem. i also having same problem.
please help me and contact [email protected]
Sorry for the delay. This is how I got it working:
.directive('disableTap', function($timeout) {
return {
link: function() {
$timeout(function() {
// Find google places div
_.findIndex(angular.element(document.querySelectorAll('.pac-container')), function(container) {
// disable ionic data tab
container.setAttribute('data-tap-disabled', 'true');
// leave input field if google-address-entry is selected
container.onclick = function() {
document.getElementById('autocomplete').blur();
};
});
},500);
}
};
});
I'm using Lo-Dash if more than one .pac-container exists (but you could do the same without Lo-Dash).
http://plnkr.co/edit/1VIuREWDNunaimL4qMAz?p=preview
@ch000 Looks like that with your approach the issue is solved, at least for me. Is wierd though, that only works on a real device. I mean, if you try to emulate a real device with chrome as @Jdruwe commented, the problem persists.
the vanilla/angularjs way to implement your fix in case anyone is interested:
.directive('disabletap', function($timeout) {
return {
link: function() {
$timeout(function() {
container = document.getElementsByClassName('pac-container');
// disable ionic data tab
angular.element(container).attr('data-tap-disabled', 'true');
// leave input field if google-address-entry is selected
angular.element(container).on("click", function(){
document.getElementById('type-selector').blur();
});
},500);
}
};
});
I'd like to point out this community project
https://github.com/israelidanny/ion-google-place
Seems to be a good solution
ion-google-place is working really well for me. I needed to make a few simple changes so it could use the Google Places API rather than Google's geocoder, but I've documented my changes here (https://github.com/israelidanny/ion-google-place/issues/3) and will submit a PR in the next few days.
I've been spending the day trying to get this to work with no luck. the example above http://plnkr.co/edit/1VIuREWDNunaimL4qMAz?p=preview @ch000 had doesn't work on ipad ios8 or ios 7 on iphone.
I tried your suggestion @gsabater but it only works in the browser emulators. xcode emulator and iphone actual device it won't add the data-tap-disable attribute. haven't gone down the path of the ion-google-place project yet as I'm not sure how to implement it into my map view. And was hoping to get this working. any thoughts?
I would suggest to use $interval instead of $timeout. This way you a more independent of time delays.
Instead of using custom directive and $timeout, I wrap the same code in a controller function and trigger using ng-focus on the input. Worked perfectly for me.
@kandizzy @php-engineer @gsabater @ch000 both solutions work on Chrome emulator, but persists on iOS 8.1.2 Chrome Version 39.0.2171.50.
I'm trying to understand what the blur() call is intended to do—it's not snapping the autocomplete click event back to the input form.
In the code below, event.toElement.parentElement returns the .pac-item; I'm trying to figure out how to proceed from here.
Should I write a directive that has access to scope and element to bind the input value to the text-field?
function() {
$timeout(function() {
var container = document.getElementsByClassName('pac-container');
var parent = document.getElementById('autocomplete');
// wrapping disabledtap in parent of input
// angular.element(parent).wrap('');
// leave input field if google-address-entry is selected
angular.element(container).on("click", function(event){
console.log('on click', event.toElement.parentElement, event, container);
// var target = event.target;
// return event.target
});
angular.element(parent).on('blur', function(){
console.log('inside BLUR')
})
console.log('disabletap ready')
},5000);
@mhartington the ion-google-place directive does not seem to work. However, @gsabater 's slolution only works when you relode content in Safari Developer tools.
It seems that the directive does not see the places dynamic div when you navigate to the view, but when you refresh while being on the veiw the directive adds needed class:
before refresh:

after page refresh the directive adds needed class:

Also i have noticed that if you go back and forward google just appends multiple divs:

Additi
@quipu @mhartington it seems that ion-google-place does not work with current ionic-beta14.
What version of ionic you are using ion-google-plase directive with?
Did you use it with simple way?.Test it with simple javascript.Here is a link how to use it. http://www.w3docs.com/learn-javascript/places-autocomplete.html
Hey guys! Have someone came up with solution for @raywu issue? I'm facing the same one right now..
As @ph88lee said, I just added the relevant code to a controller function that triggered using ng-focus and it worked well like so:
$scope.disableTap = function(){
container = document.getElementsByClassName('pac-container');
// disable ionic data tab
angular.element(container).attr('data-tap-disabled', 'true');
// leave input field if google-address-entry is selected
angular.element(container).on("click", function(){
document.getElementById('your_input_id').blur();
});
}
@TillaTheHun0 Hey can you paste the exact way you did it? What code did you move into a controller?
@jason-engage I took the relevant code and placed it into a function like above. So in my controller:
.controller('MyCtrl', function($scope) {
$scope.disableTap = function(){
container = document.getElementsByClassName('pac-container');
// disable ionic data tab
angular.element(container).attr('data-tap-disabled', 'true');
// leave input field if google-address-entry is selected
angular.element(container).on("click", function(){
document.getElementById('searchBar').blur();
});
};
})
I then used the ng-focus directive to execute the expression on the desired element like so:
<input id="searchBar" type="text" placeholder="Search" ng-focus="disableTap()">
This basically fires an event when the element gains focus, switches the containers 'data-tap-disabled' attribute to true. When you click the container, it removes focus, thus emulating user interaction. Hope this helps.