Permalink
Browse files

Merge pull request #1 from ericf/nzakas_geo

Added support for positionOptions, part of the W3C Geolocation API
  • Loading branch information...
2 parents 97afc52 + 139e41c commit f105120d16f48b4b66127a68e7b75b065d4d6e75 Nicholas C. Zakas committed May 9, 2011
Showing with 26 additions and 9 deletions.
  1. +4 −3 src/gallery-geo/demo/geo.html
  2. +22 −6 src/gallery-geo/js/geo.js
@@ -1,3 +1,5 @@
+<!DOCTYPE html>
+
<html>
<head>
<title>Geo Demo</title>
@@ -9,7 +11,7 @@ <h1>Geo Tests</h1>
<script type="text/javascript">
YUI({
- gallery: 'gallery-2009.12.08-22',
+ gallery: 'gallery-2011.05.04-20-03',
modules: {
'gallery-geo': {
fullpath: '../../../build/gallery-geo/gallery-geo.js',
@@ -29,11 +31,10 @@ <h1>Geo Tests</h1>
console.log(data.coords.longitude);
console.log(data.coords.accuracy);
}
- });
+ }, null, { enableHighAccuracy: true });
});
-
</script>
</body>
</html>
View
@@ -20,8 +20,11 @@
* four properties: success (true/false), coords (an object),
* timestamp, and source ("native" or "geoplugin").
* @param scope {Object} (Optional) The this value for the callback function.
+ * @param opts {Object} (Optional) The PositionOptions object passed to
+ * the getCurrentPosition function and has three optional properties:
+ * enableHighAccuracy (true/false), timeout (number), maximumAge (number).
*/
-function getCurrentPositionByAPI(callback, scope){
+function getCurrentPositionByAPI(callback, scope, opts){
navigator.geolocation.getCurrentPosition(
function(data){
callback.call(scope, {
@@ -43,9 +46,10 @@ function getCurrentPositionByAPI(callback, scope){
if (error.code == 1) { //user denied permission, so don't do anything
callback.call(scope, { success: false, denied: true });
} else { //try Geo IP Lookup instead
- getCurrentPositionByGeoIp(callback,scope);
+ getCurrentPositionByGeoIP(callback,scope);
}
- }
+ },
+ opts
);
}
@@ -56,9 +60,17 @@ function getCurrentPositionByAPI(callback, scope){
* four properties: success (true/false), coords (an object),
* timestamp, and source ("native" or "geoplugin").
* @param scope {Object} (Optional) The this value for the callback function.
+ * @param opts {Object} (Optional) The PositionOptions object passed to
+ * the getCurrentPosition function and has three optional properties:
+ * enableHighAccuracy (true/false) which is ingored, timeout (number),
+ * maximumAge (number) passed to YQL request as maxAge URL-query param.
*/
-function getCurrentPositionByGeoIP(callback, scope){
+function getCurrentPositionByGeoIP(callback, scope, opts){
+ opts || (opts = {});
+ var yqlParams = Y.Lang.isNumber(opts.maximumAge) ?
+ { _maxage: opts.maximumAge } : {};
+
Y.YQL("select * from pidgets.geoip", {
on: {
success: function(response){
@@ -82,9 +94,13 @@ function getCurrentPositionByGeoIP(callback, scope){
},
failure: function(){
callback.call(scope, { success: false });
+ },
+ timeout: function(){
+ callback.call(scope, { success: false });
}
- }
- });
+ },
+ timeout: opts.timeout
+ }, yqlParams);
}

0 comments on commit f105120

Please sign in to comment.