Planet Jonny

Wasting space since 1980


Howto: Geolocation in Firefox 3.5

Just a really quick how-to. I was playing around with geolocation services in Firefox 3.5. Its pretty easy to get the guessed location of the user but in my experience its far from accurate. I was located in Seattle while I’m actually located in Eugene Oregon. I imagine its attempting to locate me based upon my IP address but I imagine mobile devices will have better means to locate the position more accurately.

[Edit] Looks like the location is being determined by posting some data to Google (https://www.google.com/loc/json). Posting and retreived data formatted as JSON. Very interesting.

It also looks like flickr’s map is already using this to show interesting photographs in your location. Very cool idea.

Anyways, its pretty simple to do. Here’s some example javascript:

function locateMe(){
   if (navigator.geolocation){
      navigator.geolocation.getCurrentPosition(located);
   }
   else{
      alert('Your browser is not supported');
   }
}

function located(result){
   alert('Latitude: ' + result.coords.latitude + '\nLongitude: ' + result.coords.longitude);
}

function locationFailed(result){
   alert('Whoops, something broke.');
}

You can also get the accuracy of the result which is specificed in meters. There is also altitude, heading and speed to name a few. Learn more about the W3C Geolocation API Specification.


Published by jonathan, on July 1st, 2009 at 9:41 pm. Filled under: Programming. | No Comments |

iPhone BrowserCaps Config for ASP.Net

Here is a very simple BrowserCaps section to detect the iPhone in ASP.net. This is to be placed in the web.config file underneath “system.web”. Again, this is a very simple configuration that could be expanded on but suites my needs for now.

<browserCaps>
  <use var="HTTP_USER_AGENT" />
  <filter>
    <!-- iPhone -->
    <case match="iPhone">
        browser=iPhone
        frames=true
        tables=true
        cookies=true
        javascript=true
        css1=true
        css2=true
        isMobileDevice="true"
    </case>
  </filter>
</browserCaps>

This will then return “true” for calls to Request.Browser.IsMobileDevice.


Published by jonathan, on July 1st, 2009 at 8:06 am. Filled under: Programming. Tags: , , | No Comments |

Dynamic Javascript, document.write and JQuery

A project I was working on recently required me to fetch an external javascript file. Part of the issue was that after it was fetched and executed, I needed to do something with it. Adding to the problem was that the javascript file contained a bunch of calls to document.write. In fact, the only thing the javascript file had was document.write calls.

JQuery makes this pretty simple. A simple call to getScript does the whole “fetching” part.

jQuery.getScript( url, callback )

And thats that. The only question that I have is whether or not the callback function is execute after the javascript resource is done being fetched or done being executed. The documentation says “A function to be executed whenever the data is loaded successfully.” which might imply that its executed after the fetch. From the tests that I saw, it was after execution. However, my tests were so basic (document.write calls) that maybe the latency between calls was so minimal I didnt notice it.

The next problem was that the javascript was being execute and document.write was being called and was replacing everything on the page. A little Googling helped me determine that you can override the browsers document.write call with your own. The only thing is that future calls to document.write would break as well. That was fixed by storing a reference to the “built in” version and restoring it after execution. This is how it looked:

var tmpDocWrite = document.write;
document.write = function(arg){
    //some code to parse the document.write content
};
$.getScript(scripturl, function(){
    //called once the script is "gotten"
    document.write = tmpDocWrite;
});

And there you have it. Fetching javascript dynamically with JQuery is pretty simple. Overriding document.write is pretty simple as well.


Published by jonathan, on June 25th, 2009 at 7:43 pm. Filled under: Programming. Tags: , | No Comments |

Another new theme?

Yes, I go through Wordpress themes like some [insert analogy here]. I’m always experimenting with software so this is nothing new. Anyways, I hope to finally use a this theme for an extended period of time. I like dark themed web pages and the minimalistic aspect is nice because its fast and simple.

There you have it.


Published by jonathan, on June 25th, 2009 at 7:29 pm. Filled under: Uncategorized. | No Comments |