2011-01-23
Blogging activities migrated to Async.fi
2011-01-20
(Desktop) Safari & (W3C) Geolocation API
I don't know why this thing fails in desktop Safari. I'm using Modernizr (which is bundled with the highly recommended HTML5 Boilerplate) which reports that the Geolocation API is supported but I'm unable to even get any dialog asking the user for permission to geolocate (which is, if I read the draft correctly, REQUIRED to be implemented).
Also, it seems that others (quite a few people actually) have had this same problem but I have been unable to find a solution yet. Below is a snippet from the code; in desktop Safari the PositionErrorCallback (the latter cb function) gets called after timeout but no luck with PositionCallback, no matter how long the timeout value is. Other tested browsers work as expected.
Referenced in other places:
- Geolocation not workin on Safari 5.x on Windows 7/XP (Stack Overflow)
- Geolocation in Safari 5 (Stack Overflow)
- HTML 5 Geolocation with Safari on the iPhone 3.0 OS, Firefox 3.5 and Chrome (demo page, fails with desktop Safari)
(Note to self: check if Google Gears, which is still installed, is causing this?)
var position = null; $(document).ready(function() { if(!Modernizr.geolocation) { return; } navigator.geolocation.watchPosition( function(pos) { position = {}; position.lat = pos.coords.latitude; position.lng = pos.coords.longitude; position.allowed = true; init(); }, function(error) { position = {}; position.allowed = false; }, { enableHighAccuracy: false, timeout: 10000, maximumAge: 86400000 } ); checkposition(); }); function checkposition() { log("checkposition()"); if(!position) { setTimeout(function() { checkposition(); }, 1000); return; } else { if(position.allowed) { log("checkposition(): got position: " + position.lat + "," + position.lng); fetchephemeris(); } else { log("checkposition(): could not get a position, giving up"); $("#geolocate").hide(); } } }
2011-01-10
QUERY_STRING parsing in plain C
As far as I can tell (which, I'll be the first one to admit, doesn't count for that much) this code is so simple that there are no holes that could be exploited.
char * query = getenv("QUERY_STRING"); char * pair; char * key; double value; if(query && strlen(query) > 0) { pair = strtok(query, "&"); while(pair) { key = (char *)malloc(strlen(pair)+1); sscanf(pair, "%[^=]=%lf", key, &value); if(!strcmp(key, "lat")) { lat = value; } else if(!strcmp(key, "lng")) { lng = value; } free(key); pair = strtok((char *)0, "&"); } }