0

I'm developing an hybrid app with Cordova, using jQuery Mobile libraries. Since I need to show a map I used and edited the code found here but seems it doesn't recognize the first line of the code.

Geolocation.js

$(document).on("pagecreate", "#map-page", function() { //doesn't work
    alert('hello');

    function initMap() {
        var defaultLatLng = new google.maps.LatLng(44.494887, 11.342616300000032); //Bologna      
        drawMap(defaultLatLng);
    }

     function drawMap(latlng) {
         var myOptions = {
             zoom: 17,
             center: latlng,
         };

         var map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);

         var marker = new google.maps.Marker({
             position: latlng,
             map: map,
             title: "Parcheggio"
         });
    }
});

Html container is the same as the demo. The scripts I've included:

<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" src="js/geolocation.js"></script>
<script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="js/jquery.mobile-1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD91dMkAWwADchy-WY1-5O7P6nHmjGont0
&callback=initMap"></script>

I've also tried to change API key but nothing changes. Do you know how to solve this problem?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Kwr93
  • 59
  • 1
  • 9
  • You might try the approach in this answer, it provides some good information on where to place your initializing code in a Cordova app: http://stackoverflow.com/a/14109006/5633831 – Petko Bossakov Dec 12 '15 at 19:30

1 Answers1

0

You should move the event bindings in document.ready block.

$(document).ready(function(){
    $(document).on("pagecreate", "#map-page", function() {
      ....
   });
});

Additionally, include Geolocation.js after jquery includes.

Nikhil Aggarwal
  • 28,197
  • 4
  • 43
  • 59