Skip to content
Browse files

delayed loading of maps for phonegap

  • Loading branch information...
1 parent 80c21e0 commit fd3df78a759dc0d04e17d11caadffdabfe170364 @andrewtrusty andrewtrusty committed Jun 1, 2013
Showing with 35 additions and 15 deletions.
  1. +0 −1 index.html
  2. +14 −0 main.css
  3. +21 −14 map.js
View
1 index.html
@@ -7,7 +7,6 @@
<script type="text/javascript" src="phonegap.js"></script>
<script type="text/javascript" src="data/boulder.js"></script>
- <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.12&key=AIzaSyDPq9h3wwq3U6xzBeVQPPA7h2CJamlU82s&sensor=true"></script>
<script type="text/javascript" src="map.js"></script>
</head>
<body>
View
14 main.css
@@ -0,0 +1,14 @@
+html {
+ height: 100%
+}
+
+body {
+ height: 100%;
+ margin: 0;
+ padding: 0
+}
+
+#map-canvas {
+ height: 100%;
+ width: 100%;
+}
View
35 map.js
@@ -3,6 +3,10 @@ var map,
native_app = (window.location.href.indexOf('/Users/') !== -1 &&
window.location.href.indexOf('/workspace/') !== -1);
+function load_script(src){
+ var d=document,s=d.createElement('SCRIPT'),c=d.getElementsByTagName('script')[0];s.type='text/javascript';s.async=true;s.src=src;c.parentNode.insertBefore(s, c);
+}
+
function geo_success(pos) {
var lat = pos.coords.latitude,
lng = pos.coords.longitude;
@@ -40,14 +44,6 @@ function placeDataMarkers() {
}
function initialize2() {
- if (navigator.geolocation) {
- navigator.geolocation.getCurrentPosition(geo_success, geo_fail, {enableHighAccuracy:true});
- } else {
- geo_fail();
- }
-}
-
-function initialize() {
var mapOptions = {
center: new google.maps.LatLng(40.0195625603, -105.279270661),
zoom: 17,
@@ -56,13 +52,24 @@ function initialize() {
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
- // phonegap specific deviceready event
- // can't use phonegap API's (eg. geolocation) until this fires
- if (native_app) {
- document.addEventListener('deviceready', initialize2, false);
+ if (navigator.geolocation) {
+ navigator.geolocation.getCurrentPosition(geo_success, geo_fail, {enableHighAccuracy:true});
} else {
- initialize2();
+ geo_fail();
}
}
-google.maps.event.addDomListener(window, 'load', initialize);
+function initialize() {
+ load_script('https://maps.googleapis.com/maps/api/js?v=3.12&key=AIzaSyDPq9h3wwq3U6xzBeVQPPA7h2CJamlU82s&sensor=true&callback=initialize2');
+}
+
+// phonegap specific deviceready event
+// can't use phonegap API's (eg. geolocation) until this fires
+if (native_app) {
+ document.addEventListener('deviceready', initialize, false);
+} else {
+ initialize();
+}
+
+
+

0 comments on commit fd3df78

Please sign in to comment.
Something went wrong with that request. Please try again.