Strange Symphonies The best way to predict the future is to invent it

Related tags

28May/100

WP Ajax Query v0.1 Released

WP Ajax Query allows you to query your WordPress database using the same query paramaters you would use for WP_Query, and return a JSON representation of the query results. This allows developers to easily interface with WordPress without having to relearn a new API.

Download Now

Download Now or read more about WP Ajax Query (WordPress Plugin Page).

15May/100

git-deploy Released

I am a big fan of Capistrano and in general, software deployment tools. Capistrano works by connecting to your server, and updating the software there.

Most of my clients get their hosting from a shared server hosting package, where the server is shared amongst multiple people. This is great, as it lowers the cost of hosting tremendously, but also the number of features the server comes with is reduced. Most shared server hosting providers allow FTP.

Sadly Capistrano requires one to have SSH access to the server. Thus Capistrano, isn't a feasible tool to use. Unable to find a substitute, I developed my own called git-deploy.

git-deploy will interact with git to only update relevant files on the server via FTP or SSH.

For example, if you only updated on file in your source code, you only need to upload one file, and not the whole directory. This makes uploading, more time and bandwidth efficient. Especially for time, as the script can be run from the command line, so you don't need to launch your upload program, select which files to upload, drag and drog, and wait. A lot of time can be saved.

This is done by storing a file called REVISION on the server, which we can compare with on the local machine.

I am personally using it now on this website, and other production sites.

I am planning to create a Ruby Gem out of the plugin, but unfortunately the name git-deploy was taken. I am still looking for a new name, so if you have a suggestion, just drop me a comment.

git-deploy is licensed under an MIT License, so feel free to use, change, and build on top of my code.

To find out more about git-deploy, and how to set it up visit its GitHub page.

Happy Deploying!

13Nov/090

Geolocation with navigator.geolocation

The W3C have been working on a Geolocation API Specification to incorporate geolocation into the browser via a new variable, navigator.geolocation.

navigator.geolocation can provide us with the following details:

  • latitude
  • longitude
  • altitude
  • accuracy
  • altitudeAccuracy
  • heading
  • speed

Mozilla Firefox v3.5 introduced navigator.geolocation, and so far Mozilla Firefox has been the only browser implementing it.

Thanks to Mozilla Firefox v3.5 we now have Location-Aware Browsing! Click here for an example. A bar will drop from the top prompting you that "blog.aizatto.com wants to know your location" with options on the right hand side. Click on "Share location".

Making Your Application Location Aware

I am going to use my sample HTML file in my previous article Geolocation with Google AJAX API (uploaded file).

This allows us to reuse the Google Reverse Geocoding.

It has been reproduced here for easy reference:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
  <title>Geolocation with Google AJAX API</title>
</head>
<script src="http://www.google.com/jsapi?key=ABCDEF" type="text/javascript"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>

<script language="Javascript" type="text/javascript">
    //<![CDATA[

    function OnLoad() {
      var geocoder = new google.maps.Geocoder();

      if (google.loader.ClientLocation) {
        document.body.innerHTML += 'google.loader.ClientLocation.latitude ' + google.loader.ClientLocation.latitude + '<br />';
        document.body.innerHTML += 'google.loader.ClientLocation.longitude ' + google.loader.ClientLocation.longitude + '<br />';
        document.body.innerHTML += 'google.loader.ClientLocation.address.city ' + google.loader.ClientLocation.address.city + '<br />';
        document.body.innerHTML += 'google.loader.ClientLocation.address.country ' + google.loader.ClientLocation.address.country + '<br />';
        document.body.innerHTML += 'google.loader.ClientLocation.address.country_code ' + google.loader.ClientLocation.address.country_code + '<br />';
        document.body.innerHTML += 'google.loader.ClientLocation.address.region ' + google.loader.ClientLocation.address.region  + '<br />';
        document.body.innerHTML += '<a href="http://maps.google.com/maps?q=' + google.loader.ClientLocation.latitude + ',+' + google.loader.ClientLocation.longitude + '>Open Location in Google Maps</a><br />';
        geocoder.geocode({'latLng': new google.maps.LatLng(google.loader.ClientLocation.latitude, google.loader.ClientLocation.longitude)}, function (results, status) {
          if (status == google.maps.GeocoderStatus.OK) {
            if (results[0]) {
              document.body.innerHTML += 'google.maps.Geocoder ' + results[0].formatted_address;
            }
          } else {
            document.body.innerHTML += 'Geocoder failed due to: ' + status;
          }
        });
      } else {
        document.body.innerHTML += 'Cannot find location';
      }
    }
    google.setOnLoadCallback(OnLoad);

    //]]>
</script>
<body>
</body>
</html>

Using navigator.geolocation

Its time to replace OnLoad again:

    function OnLoad() {
      var geocoder = new google.maps.Geocoder();

      if (navigator.geolocation) {
        document.body.innerHTML += 'Calling <code>navigator.geolocation.getCurrentPosition</code><br />';
        navigator.geolocation.getCurrentPosition(function(position) {
          document.body.innerHTML += 'position.coords.latitude ' + position.coords.latitude + '<br />';
          document.body.innerHTML += 'position.coords.longitude ' + position.coords.longitude + '<br />';
          document.body.innerHTML += 'position.coords.accuracy ' + position.coords.accuracy + '<br />';
          document.body.innerHTML += 'position.coords.altitude ' + position.coords.altitud + '<br />';
          document.body.innerHTML += 'position.coords.altitudeAccuracy ' + position.coords.altitudeAccuracy + '<br />';
          document.body.innerHTML += 'position.coords.heading ' + position.coords.heading + '<br />';
          document.body.innerHTML += 'position.coords.speed ' + position.coords.speed + '<br />';
          document.body.innerHTML += '<a href="http://maps.google.com/maps?q=' + position.coords.latitude + ',+' + position.coords.longitude + '>Open Location in Google Maps</a><br />';
          geocoder.geocode({'latLng': new google.maps.LatLng(position.coords.latitude, position.coords.longitude)}, function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
              if (results[0]) {
                document.body.innerHTML += 'google.maps.Geocoder ' + results[0].formatted_address;
              }
            } else {
              document.body.innerHTML += 'Geocoder failed due to: ' + status;
            }
          });
        }, function() {
          document.body.innerHTML += 'Cannot find location' + '<br />';
        });
      } else {
        document.body.innerHTML += 'Cannot find location' + '<br />';
      }
    }

Similar to the Geolocation with Google AJAX APIs we have to test whether the navigator.geolocation variable exists, this is done on Line 4.

If it exists. We proceed to call the navigator.geolocation.getCurrentPosition method. getCurrentPosition takes 3 arguments, with the last 2 being optional. For more details about the navigator.geolocation.getCurrentPosition visit the W3C Geolocation API Specification. The first two arguments accept a function to callback.

The first argument specifies whether the it was successful in finding the location.
The second argument handles any errors that may occur. For example, time outs.

Reverse Geocoding

          geocoder.geocode({'latLng': new google.maps.LatLng(position.coords.latitude, position.coords.longitude)}, function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
              if (results[0]) {
                document.body.innerHTML += 'google.maps.Geocoder ' + results[0].formatted_address;
              }
            } else {
              document.body.innerHTML += 'Geocoder failed due to: ' + status;
            }
          });

Once again on lines 15 to 23, I use the Google Maps API to reverse geocode the address based on the supposed latitude and longitude of the user.

I changed line 15 to use variables used for latitude and longitdue. Otherwise, its exactly the same as the Geolocation with Google AJAX API.

Conclusion

That wasn't so hard now was it? Why don't you give your location aware browser a try?