I am developing a mobile app using phonegap. I want to develop online as well as offline version of it. In online version, the App connects to google maps API and in offline version, it should skip loading the Maps and continue loading rest of the page elements. How can I check the connectivity to google maps API.
I have following function to load the Maps:
function initialize() {
var myLatlng = new google.maps.LatLng(98,-33);
var mapOptions = {
zoom: 11,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'marker'
});
var infowindow = new google.maps.InfoWindow({
content: "<div style='width:80px;'>Your Location</div>",
minWidth: 500
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
When I run the App when there is internet connection, it works fine, but when there is no connection, it gives error 'Google is not defined' and it doesn't load the page as well. Please tell how to check the connection. I tried using navigator.onLine, but it isn't useful. Thanks!