From e6e70c5b5f761d5b30abf42e92c40c138b773af6 Mon Sep 17 00:00:00 2001 From: NightHawk32 Date: Wed, 2 Dec 2015 15:38:39 -0500 Subject: [PATCH] GPS map checks for online status of the device, BUGFIX: place marker on GPS position and center map --- tabs/gps.js | 19 ++++++++---- tabs/map.html | 80 +++++++++++++++++++++++++-------------------------- 2 files changed, 53 insertions(+), 46 deletions(-) diff --git a/tabs/gps.js b/tabs/gps.js index 60d3a13a..b2bc4da1 100644 --- a/tabs/gps.js +++ b/tabs/gps.js @@ -67,6 +67,7 @@ TABS.gps.initialize = function (callback) { $('td', row).eq(2).find('progress').val(GPS_DATA.cno[i]); } + var message = { action: 'center', lat: lat, @@ -74,13 +75,21 @@ TABS.gps.initialize = function (callback) { }; var frame = document.getElementById('map'); - if(lat != 0 && lon != 0){ - frame.contentWindow.postMessage(message, '*'); - $('#waiting').hide(); - $('#loadmap').show(); + if (navigator.onLine) { + $('#connect').hide(); + + if(lat != 0 && lon != 0){ + frame.contentWindow.postMessage(message, '*'); + $('#loadmap').show(); + $('#waiting').hide(); + }else{ + $('#loadmap').hide(); + $('#waiting').show(); + } }else{ + $('#connect').show(); + $('#waiting').hide(); $('#loadmap').hide(); - $('#waiting').show(); } } diff --git a/tabs/map.html b/tabs/map.html index 2e8ba73c..27bb7698 100644 --- a/tabs/map.html +++ b/tabs/map.html @@ -31,44 +31,46 @@ break; case 'center': map.setCenter(new google.maps.LatLng(e.data.lat, e.data.lon)); + marker.setPosition( new google.maps.LatLng( e.data.lat, e.data.lon ) ); + map.panTo( new google.maps.LatLng( e.data.lat, e.data.lon ) ); } } catch (e) { console.log('message error'); } }); - function loadMapScript() { - var script = document.createElement('script'); - script.type = 'text/javascript'; - script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true&callback=initialize'; - document.head.appendChild(script); - } + function loadMapScript() { + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true&callback=initialize'; + document.head.appendChild(script); + } -window.onload = loadMapScript; + window.onload = loadMapScript; -var map; -function initialize() { + var map; + var marker; - var mapOptions = { - zoom: 17, - zoomControl: false, - streetViewControl: false, - // mapTypeId: google.maps.MapTypeId.SATELLITE, - center: {lat: 53.570645, lng: 10.001362} - }; - map = new google.maps.Map(document.getElementById('map-canvas'), - mapOptions); + function initialize() { - var image = { - url: '../images/icons/cf_icon_position.png', - scaledSize: new google.maps.Size(70, 70) - }; + var mapOptions = { + zoom: 17, + zoomControl: false, + streetViewControl: false, + center: {lat: 53.570645, lng: 10.001362} + }; + map = new google.maps.Map(document.getElementById('map-canvas'),mapOptions); + + var image = { + url: '../images/icons/cf_icon_position.png', + scaledSize: new google.maps.Size(70, 70) + }; -var marker = new google.maps.Marker({ - icon : image, - position: new google.maps.LatLng(53.570645, 10.001362), - map:map - }); + marker = new google.maps.Marker({ + icon : image, + position: new google.maps.LatLng(53.570645, 10.001362), + map:map + }); // You can use a LatLng literal in place of a google.maps.LatLng object when @@ -76,23 +78,19 @@ var marker = new google.maps.Marker({ // position will be available as a google.maps.LatLng object. In this case, // we retrieve the marker's position using the // google.maps.LatLng.getPosition() method. - var infowindow = new google.maps.InfoWindow({ - content: '

Your Location: ' + marker.getPosition() + '

' - }); + var infowindow = new google.maps.InfoWindow({ + content: '

Your Location: ' + marker.getPosition() + '

' + }); - google.maps.event.addListener(marker, 'click', function() { - infowindow.open(map, marker); - }); + google.maps.event.addListener(marker, 'click', function() { + infowindow.open(map, marker); + }); - window.addEventListener('message', function(e) { - - var data = e.data; - var origin = e.origin; -}); + window.addEventListener('message', function(e) { + var data = e.data; + var origin = e.origin; + }); } - // sandbox docs1: https://github.com/GoogleChrome/chrome-app-samples/tree/master/samples/sandbox - // sandbox docs1: https://github.com/GoogleChrome/chrome-app-samples/tree/master/samples/sandboxed-content -