etodanik / ion-google-place

Ionic directive for a location dropdown that utilizes google maps
MIT License
251 stars 201 forks source link

ion-google-place cannot work with ng-cordova-oauth #63

Open chicheongweng opened 8 years ago

chicheongweng commented 8 years ago

I can confirm ion-google-place project works fine on iPhone until I add ng-cordova-oauth. ion-google-place and ng-cordova-oauth work fine independently.

As soon as I add the following line to www/index.html, I am getting google.maps undefined error. Any idea why?

0 103484 error Error: undefined is not an object (evaluating 'new google.maps.Geocoder') link@http://192.168.1.197:8100/lib/ion-google-place/ion-google-place.js:17:51 invokeLinkFn@http://192.168.1.197:8100/lib/ionic/js/ionic.bundle.js:21830:15 nodeLinkFn@http://192.168.1.197:8100/lib/ionic/js/ionic.bundle.js:21330:23 compositeLinkFn@http://192.168.1.197:8100/lib/ionic/js/ionic.bundle.js:20721:23 compositeLinkFn@http://192.168.1.197:8100/lib/ionic/js/ionic.bundle.js:20725:24 nodeLinkFn@http://192.168.1.197:8100/lib/ionic/js/ionic.bundle.js:21325:35 compositeLinkFn@http://192.168.1.197:8100/lib/ionic/js/ionic.bundle.js:20721:23 nodeLinkFn@http://192.168.1.197:8100/lib/ionic/js/ionic.bundle.js:21325:35 compositeLinkFn@http://192.168.1.197:8100/lib/ionic/js/ionic.bundle.js:20721:23 publicLinkFn@http://192.168.1.197:8100/lib/ionic/js/ionic.bundle.js:20596:45 appendViewElement@http://192.168.1.197:8100/lib/ionic/js/ionic.bundle.js:56754:11 render@http://192.168.1.197:8100/lib/ionic/js/ionic.bundle.js:54859:58 init@http://192.168.1.197:8100/lib/ionic/js/ionic.bundle.js:54779:26 render@http://192.168.1.197:8100/lib/ionic/js/ionic.bundle.js:56607:18 register@http://192.168.1.197:8100/lib/ionic/js/ionic.bundle.js:56565:16 updateView@http://192.168.1.197:8100/lib/ionic/js/ionic.bundle.js:62210:31 http://192.168.1.197:8100/lib/ionic/js/ionic.bundle.js:62187:21 $broadcast@http://192.168.1.197:8100/lib/ionic/js/ionic.bundle.js:29345:33 http://192.168.1.197:8100/lib/ionic/js/ionic.bundle.js:49189:32 processQueue@http://192.168.1.197:8100/lib/ionic/js/ionic.bundle.js:27747:30 http://192.168.1.197:8100/lib/ionic/js/ionic.bundle.js:27763:39 $eval@http://192.168.1.197:8100/lib/ionic/js/ionic.bundle.js:29026:28 $digest@http://192.168.1.197:8100/lib/ionic/js/ionic.bundle.js:28837:36 $apply@http://192.168.1.197:8100/lib/ionic/js/ionic.bundle.js:29131:31 http://192.168.1.197:8100/lib/ionic/js/ionic.bundle.js:25266:30 eventHandler@http://192.168.1.197:8100/lib/ionic/js/ionic.bundle.js:16451:25 dispatchEvent@[native code] triggerMouseEvent@http://192.168.1.197:8100/lib/ionic/js/ionic.bundle.js:2906:20 tapClick@http://192.168.1.197:8100/lib/ionic/js/ionic.bundle.js:2895:20 tapTouchEnd@http://192.168.1.197:8100/lib/ionic/js/ionic.bundle.js:3022:13,

Here is my complete index.html

<!DOCTYPE html>

``` ```
chicheongweng commented 8 years ago

Narrowed down the index.html to as follows. The ion-google-place directive only works if I remove the line lib/ng-cordova-oauth/dist/ng-cordova-oauth.min.js Otherwise I will get error Error: undefined is not an object (evaluating 'new google.maps.Geocoder')

<!DOCTYPE html>

``` ```
pdfowler commented 8 years ago

This problem appears to be much wider than just how ion-google-place works, since the ngCordovaOauth overrides the $window.google variable, which is the standard variable used for any number of google based services.

Although this may not solve your problem (eg: you are using google+ OAuth), I've worked around it as follows:

  1. Change your script imports to the following:
    <!--<script src="lib/ng-cordova-oauth/lib/ng-cordova-oauth.js"></script>-->
    <!-- 
        Disable import of full OAuth Library b/c it overwrites the `window.google` variable used for google maps.
        Instead, just import the OAuth Utilities file, along with the OAuth Providers that you require
    -->
    <script src="lib/ng-cordova-oauth/src/utility.js"></script>
    <script src="lib/ng-cordova-oauth/src/oauth.facebook.js"></script>
  1. When initializing your app, import only the specific OAuth providers you need, not ngCordovaOauth as a whole:
    angular.module('myapp', ['oauth.facebook']);

Figured I'd share this here while I look for a related issue in the ngCordovaOauth project

Edison767e commented 8 years ago

@fatty1380 Thanks for sharing! we had similar problem with ngCordovaOauth