Skip to content

Commit

Permalink
Provide map fallback on GeoLocation error, improvements to plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkaneda committed Dec 23, 2011
1 parent c57a629 commit 5e77dcd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 35 deletions.
14 changes: 11 additions & 3 deletions demos/ext_location/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,28 @@
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map($("#map_canvas").get(0), myOptions);

} else {
setDisplay('Device not capable of geo-location.');
}
}, function(){
var latlng = new google.maps.LatLng(37.48, -122.24);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map($("#map_canvas").get(0), myOptions);
});

if (lookup) {
setDisplay('Looking up location…');

}
});
</script>
<style type="text/css" media="screen">
#map_canvas {
height: 200px;
height: 100%;
background-color: rgba(255,255,255,.3);
}
</style>
Expand All @@ -67,7 +75,7 @@ <h1>Geo Location</h1>
</ul>
<div class="info"></div>
</div>
<div id="map" class="notransform">
<div id="map">
<div class="toolbar">
<h1>Map</h1>
<a href="#" class="back">Back</a>
Expand Down
47 changes: 15 additions & 32 deletions extensions/jqt.location.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,27 @@
/*
_/ _/_/ _/_/_/_/_/ _/
_/ _/ _/ _/_/ _/ _/ _/_/_/ _/_/_/
_/ _/ _/_/ _/ _/ _/ _/ _/ _/ _/ _/
_/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/
_/ _/_/ _/ _/ _/_/ _/_/_/ _/_/_/ _/ _/
_/
_/
Created by David Kaneda <http://www.davidkaneda.com>
Documentation and issue tracking on Google Code <http://code.google.com/p/jqtouch/>
Special thanks to Jonathan Stark <http://jonathanstark.com/>
and pinch/zoom <http://www.pinchzoom.com/>
(c) 2009 by jQTouch project members.
See LICENSE.txt for license.
*/

(function($) {
if ($.jQTouch)
{
$.jQTouch.addExtension(function Location(){

var latitude, longitude, callback;
var latitude, longitude, callback, callback2;

function checkGeoLocation() {
return navigator.geolocation;
}
function updateLocation(fn) {
if (checkGeoLocation())
function updateLocation(fn, fn2) {
if (navigator.geolocation)
{
callback = fn;
navigator.geolocation.getCurrentPosition(savePosition);
callback2 = fn2;
navigator.geolocation.getCurrentPosition(savePosition, failResponse);
return true;
} else {
console.log('Device not capable of geo-location.');
fn(false);
return false;
}
}
}
function failResponse(error){
if (callback2) {
callback2(error);
}
}
function savePosition(position) {
latitude = position.coords.latitude;
Expand All @@ -53,7 +35,8 @@
return {
latitude: latitude,
longitude: longitude
}
};

} else {
console.log('No location available. Try calling updateLocation() first.');
return false;
Expand All @@ -62,7 +45,7 @@
return {
updateLocation: updateLocation,
getLocation: getLocation
}
};
});
}
})(jQuery);
})($);

0 comments on commit 5e77dcd

Please sign in to comment.