Monaca Onsen UI Discord Chat Github Repo

cordova google map plugin not shown map



  • @Abiraman-Ramanathan

    I understand all your points, what I was trying to show and it will easily work in Onsen 1.x, is that Google Maps do in fact work with Onsen. Onsen is a UI framework for hybrid apps. All of these apps run in the webview - think mini-web browsers wrapped by Cordova for native extensions. My point is that Onsen’s UI components simply map to web elements with excellent CSS and JS backing them - hence Angular integration, etc.

    We already discussed how you would use pageinit instead of the show event. I use the JS api because it is the simplest way to demonstrate that the maps are functioning in Onsen because Cordova plugins do not work in codepen nor the Monaca IDE - you must have a device to test on.

    For more information specific to a Cordova plugin as this is an Onsen forum, I would recommend looking here:

    https://github.com/mapsplugin/cordova-plugin-googlemaps

    Lastly, the cordova google maps plugin is using the Android SDK which is a simply a wrapper for that api. It is still a generating a map in the webview. The only difference between the Android SDK and JS api is data generated per map tile (png vs vector). This is why I used the JS api to show you that it will work in an Onsen page. The problem is not with Onsen, but within your implementation of the plugin.

    For a complete tutorial for the Cordova Maps plugin with Monaca, please reference here: https://github.com/mapsplugin/cordova-plugin-googlemaps/wiki/Tutorial-for-Monaca



  • @munsterlander

    screenshot of cordova app without onsen ( code source : https://github.com/mapsplugin/cordova-plugin-googlemaps/wiki/Tutorial-for-Monaca (9th step) )

    0_1455870827363_Screenshot_2016-02-19-13-32-49.png

    screenshot of cordova app with onsen ( code source : mapepage)

    0_1455871002816_Screenshot_2016-02-19-13-35-53.png
    I did not get any error in onsen ui.But map not displayed after page push.I tried with pageinit
    but no map on this page… this is my problem .I already used this plugin in ionic but it was working well.
    I cant use javascript api for android app because of security for api key.Any one can use my api key. So i move to this plugin.help me



  • @Abiraman-Ramanathan Can you post your whole js code? What is happening, in my opinion, is the same that I posted about here: http://stackoverflow.com/questions/35123385/onsen-2-0-adding-event-listener-to-ons-switch-with-javascript

    The map div is not attached to the DOM in time for the asynchronous calls of the Google maps api - plugin or other api, it doesn’t matter. The call to display the map cannot find the object and thus does not display. This is why it disappears (probably) when you are using Onsen. We wil probably need to rewrite your map call function a bit.



  • @munsterlander

    My app.js .

    /* This js corresponds to initializing the and mapping the page corresponds to the controller */
    var app = angular.module('app', ['onsen']);
    app.run(function ($rootScope, $http) {
        document.addEventListener("pageinit", function (event) {
              if(event.target.id=='mappage'){
            console.log('mappage');
            var mapDiv = document.getElementById("map_canvas");
            console.log(mapDiv); //DOM element is printing while code execute
                var map = plugin.google.maps.Map.getMap(mapDiv);
              }
        });
       
            // Use Cordova handler
            document.addEventListener('backbutton', function (e) {
                // Handle backbutton event
                e.preventDefault();
            }, false);
    
        }, false);
    
    });
    app.controller('BidMapController', function ($scope, $rootScope, $http, ServiceUrl) { });
    

    map_canvas DOM element is print after executes pageinit.

    My index.html

    <!DOCTYPE html>
    <!-- CSP support mode (required for Windows Universal apps): https://docs.angularjs.org/api/ng/directive/ngCsp -->
    <html lang="en" ng-app="app" ng-csp>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height" />
        <meta http-equiv="Content-Security-Policy" content="default-src *; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'">
            <link href='https://fonts.googleapis.com/css?family=Roboto:400,300,500,700' rel='stylesheet' type='text/css'>
        <!-- JS dependencies (order matters!) -->
        <script src="scripts/platformOverrides.js"></script>
        <script src="lib/angular/angular.js"></script>
        <script src="lib/onsen/js/onsenui.js"></script>
        <!-- CSS dependencies -->
        <link rel="stylesheet" href="lib/onsen/css/onsenui.css" />
        <link rel="stylesheet" href="lib/onsen/css/onsen-css-components-blue-basic-theme.css" />
        <!-- CSP support mode (required for Windows Universal apps) -->
        <link rel="stylesheet" href="lib/angular/angular-csp.css" />
         <link rel="stylesheet" href="lib/font_awesome/css/font-awesome.min.css">
         <link rel="stylesheet" href="lib/ionicons/css/ionicons.min.css">
         <link rel="stylesheet" href="css/style.css">
        <link rel="stylesheet" href="css/spinner.css">
        <!-- --------------- App init --------------- -->
    </head>
    
    <body>
        <!-- Cordova reference -->
        <script src="cordova.js"></script>
        <script src="js/app.js"></script>
        <!-- -->
    
        <div ng-show="pageLoading" id="page_loader" data-loading>
            <div id="loader_spinner">
                <div class="ispinner white large animating">
                    <div class="ispinner-blade"></div>
                    <div class="ispinner-blade"></div>
                    <div class="ispinner-blade"></div>
                    <div class="ispinner-blade"></div>
                    <div class="ispinner-blade"></div>
                    <div class="ispinner-blade"></div>
                    <div class="ispinner-blade"></div>
                    <div class="ispinner-blade"></div>
                    <div class="ispinner-blade"></div>
                    <div class="ispinner-blade"></div>
                    <div class="ispinner-blade"></div>
                    <div class="ispinner-blade"></div>
                </div> 
            </div>
        </div>
    <ons-sliding-menu  ng-if="!isLogin" main-page="login/login.html" side="left" type="overlay" max-slide-distance="1px" var="app.slidingMenu" ></ons-sliding-menu>
    <ons-sliding-menu  ng-if="isLogin" var="app.slidingMenu" menu-page="menu.html" main-page="home/home.html" side="left" type="overlay" max-slide-distance="250px" ></ons-sliding-menu>
    
    </body>
    </html>
    


  • That all looks ok. Have you tried the

    ons.ready()
    

    Function instead of using the event listener but in the same location? Also, have you tried to get the map to display on a simple page that isn’t using any advanced elements, i.e.sliding menus? Unfortunately, I do not have the design environment that you have or the account to run the maps plugin, so I am limited on what I can do. I still contend that if your maps API is functioning, then it can’t find the element in the DOM and that is why it is not showing. That or a CSS height / width issue could be happening.

    I say this, because I struggled with the identical problem here:

    http://stackoverflow.com/questions/35142178/monaca-onsen-2-0-charts-libraries-not-working-svg-and-canvas-in-ons-navig

    Which was fixed with info from @Fran-Diox here:

    http://stackoverflow.com/questions/35123385/onsen-2-0-adding-event-listener-to-ons-switch-with-javascript

    Edit: Try this, I am curious to see what will happen:

        document.addEventListener("pageinit", function (event) {
              if(event.target.id=='mappage'){
                  ons.ready(function() {
                       var mapDiv = document.getElementById("map_canvas");
                       var map = plugin.google.maps.Map.getMap(mapDiv);
                   });
              }
        });
    


  • @munsterlander
    1.I tried all the method below but map not displayed.But “map_canvas” is detected in All method.
    2.It is not a width and height problem because i give this style="width:100%;height:400px;position: relative !important" for map_canvas.

    1. i dont have time to test onsen ui and report you .So reply me asap…

    Method 1.

    document.addEventListener("pageinit", function (event) {
            if (event.target.id == 'mappage') {
                ons.ready(function () {
                console.log('mappage');
              var mapDiv=  document.querySelector('#map_canvas');
                console.log(mapDiv);
                var map = plugin.google.maps.Map.getMap(mapDiv);
                });
            }
        });
    

    Method 2.

    document.addEventListener("pageinit", function (event) {
            if (event.target.id == 'mappage') {
                ons.ready(function () {
                console.log('mappage');
                var mapDiv = document.getElementById("map_canvas");
                console.log(mapDiv);
                var map = plugin.google.maps.Map.getMap(mapDiv);
                });
            }
        });
    

    Method 3

     document.addEventListener("pageinit", function (event) {
            if (event.target.id == 'mappage') {
                ons.ready(function () {
                console.log('mappage');
                var mapDiv = $("map_canvas");
                console.log(mapDiv);
                var map = plugin.google.maps.Map.getMap(mapDiv);
                });
            }
        });
    

    Method 4.

    app.controller('BidMapController', function ($scope, $rootScope, $http, ServiceUrl) {
         ons.ready(function () {
                var mapDiv = document.getElementById("map_canvas");
                var map = plugin.google.maps.Map.getMap(mapDiv);
        });
    });
    

    Method 5.

    app.controller('BidMapController', function ($scope, $rootScope, $http, ServiceUrl) {
         document.addEventListener("pageinit", function (event) {
            if (event.target.id == 'mappage') {
                ons.ready(function () {
                console.log('mappage');
                var mapDiv = $("map_canvas");
                console.log(mapDiv);
                var map = plugin.google.maps.Map.getMap(mapDiv);
                });
            }
        });
    });
    

    Any thing else … It tried all the method.
    In this method map was initiated but not displayed.
    Proof for DOM element:
    0_1455943980644_Screen Shot 2016-02-20 at 10.21.34 am.png



  • @munsterlander

    I found solution for this problem.

    1. Map is loading in background position. Onsen ui background is overlapping on map so map is not displayed in that page.

    Solution :

    angular.element(document.querySelectorAll('.page__background')).css('background-color', 'transparent', 'important');
                    angular.element(document.querySelector('.menu-container')).children().css('background-color', 'transparent', 'important');
    

    Thank you MR.munsterlander for your good effort.



  • Hey! At least it is working! I had a similar issue trying to get those charts to show within a navigator below a list. They kept getting pushed to the side. Oh well, at least you have the solution now.



  • I have the same issue, Show event is not fired, i am using onsen 1.x,
    Here is my code,

      document.addEventListener("show", function (event) {
                    if (event.target.id == "service_requests-page") {
                       alert("init service_requests-page");
                    }
                }, false);
    
    

    Any one can help ?



  • @Omar-Hassan Try this and report back the results:

    document.addEventListener("show", function (event) {
       console.log(event.target.id);
    },false);