• Entries (RSS)
  • Comments (RSS)

Calculate the distance between two sets of coordinates using JavaScript

Posted by | Posted in JavaScript Code | Posted on 05-02-2010

Tagged Under : , , ,

Here’s some code which allows you to calculate the distance in miles, kilometres or nautical miles between two sets of coordinates:

/*    Function Name: distance()
Function Description: Calculates the distance between two sets of coordinates.

@Author: Adam Williams <adam.williams@awdigital.eu>
@License: Creative Commons Attribution-Share Alike 2.0 UK: England & Wales - http://creativecommons.org/licenses/by-sa/2.0/uk/
@Example: distance(53.61857936489517, -1.4501953125, 65.82078234733756, -172.265625, 'm');

*/

/* Dependant functions */

function deg2rad(angle) {
return (angle * Math.PI / 180);
}

function rad2deg (angle) {
return (angle / Math.PI) * 180;
}

/* Main function */

function distance(lat1, lon1, lat2, lon2, unit) {
var theta, dist, miles;
theta = lon1 - lon2;

dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2)) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta));
dist = Math.acos(dist);
dist = rad2deg(dist);
miles = dist * 60 * 1.1515;
unit = unit.toUpperCase();

if (unit === "K") {
return (miles * 1.609344);
} else if (unit === "N") {
return (miles * 0.8684);
} else {
return miles;
}
}

You can download the code if you don’t want to copy and paste: distance.js

Any feedback welcomed.

Cheers! :-)

Hash key (#) on Mac Keyboard on Windows

Posted by | Posted in Tutorials | Posted on 21-01-2010

Tagged Under :

If you’ve installed Windows on your Mac using Bootcamp and are desperately looking for the hash symbol (#) you will eventually discover that it is not on your keyboard and the Mac short cut of Alt + 3 doesn’t work.

However, if you try Ctrl + Alt + 3 it should work just fine :) .

Happy coding!

Download Google Chrome for Mac

Posted by | Posted in General | Posted on 08-12-2009

Tagged Under : , ,

Well today is good news day for Macheads everywhere. Google has just released a Mac version of their Chrome browser.

Download it from http://www.google.com/chrome/intl/en/huzzah.html.

From the Google announcement:

Here are a few fun facts from us on the Google Chrome for Mac team:

  • 73,804 lines of Mac-specific code written
  • 29 developer builds
  • 1,177 Mac-specific bugs fixed
  • 12 external committers and bug editors to the Google Chrome for Mac code base, 48 external code contributors
  • 64 Mac Minis doing continuous builds and tests
  • 8,760 cups of soft drinks and coffee consumed
  • 4,380 frosted mini-wheats eaten

I have yet to download and test the new version of the browser, but once I do I’ll chuck a post on with my thoughts about it.

Happy browsing :-)

How to solve the “Server certificate verification failed: issuer is not trusted” SVN error in Coda for Mac

Posted by | Posted in Tutorials | Posted on 30-11-2009

Tagged Under : , , ,

If you’re checking out an SSL hosted SVN repository in Coda you may receive the following error:

Server certificate verification failed: issuer is not trusted

This error is because the SSL hasn’t been trusted by your system. To fix this complete the following:

  • Open Terminal (Applications/Utilities/Terminal)
  • Enter the following: svn list https://www.example.com/svn/ –username user replacing the URL and username with those for your server, then hit enter.
  • press p if the message appears asking you to accept the SSL certificate, then hit enter.
  • Enter your password, if required, then enter.
  • You can now exit and return to Coda where you should now be able to checkout the repo successfully.

I hope this helps you fellow Coda users :-) .

Google wave invites

Posted by | Posted in General | Posted on 24-11-2009

Hi,

I’ve got 7 Google Wave invites to give away.

If you would like one please get in touch.

Ask Adam!

Posted by | Posted in General | Posted on 20-11-2009

If you have any general web design, CSS, JavaScript, PHP or MySQL questions you can now ask Adam. Just complete the form on http://root-servers.co.uk/ask-adam and I will reply via the blog.

How to right click using the Macbook trackpad on Windows 7

Posted by | Posted in Tutorials | Posted on 25-10-2009

Tagged Under : , , ,

As I mentioned in my previous post I’ve just installed Windows 7 on my Macbook and one of the issues I’ve come across is the lack of a right click button on the trackpad.

Here’s a way to get right clicking without having to plug in an external mouse:

  • Make sure you have run the Bootcamp installer from the Mac OS X disk so that all of the correct drivers are loaded for Windows 7.
  • Right clicking should now be possible by placing two fingers on the trackpad, then click the trackpad button.
  • Be careful not to install future trackpad updates via Windows Update as I’ve heard that this could disable the ability to right click.

How to enable sound on Windows 7 on Mac (iMac / Macbook)

Posted by | Posted in Tutorials | Posted on 25-10-2009

Tagged Under : , , , ,

Hi,

I just bought a copy of Windows 7 Ultimate and decided to set it up on my Macbook (running OS X 10.5) using Bootcamp.

The install was very straight forward and the graphics and networking worked out of the box. The only issue I had was getting the sound to work. After a bit of googling and experimentation I found the following solution to work:

  • Go to http://www.realtek.com/downloads/ and click on the High Definition Audio Codecs link.
  • Download the file and run the installer.
  • Restart your Mac and when Windows 7 boots back up you should be greeted with the Windows 7 startup theme.

I’m also told that if you use your Mac OS X disk, the drivers are also on there.

I would recommend that you run the Bootcamp utility from the Mac install disk after installing Windows 7 as it maps the keyboard correctly, installs drivers from bluetooth, infrared etc as well as providing a control panel to allow you to choose which OS to boot to etc.

How to set error level and output in PHP

Posted by | Posted in Tutorials | Posted on 14-10-2009

Tagged Under : , , , ,

You can set the error reporting level in PHP and also define whether it is displayed to the user or saved to a log file.

The level can be defined either in the php.ini, .htaccess or directly inside a PHP script.

The logging level options are:

  • E_ALL – will log every error, including notice messages
  • E_WARNING – will log errors which are not fatal
  • E_ERROR – Will log fatal errors
  • E_NOTICE – Will log notices only, such as using a constant which hasn’t been defined.

The logging levels can be combined to suit using ampersands (&). The tilder character (~) can also be used before an option to exclude it. An example would be

error_reporting E_ALL & ~E_NOTICE

The above example will show all errors except notices. This is probably the combination you are most likely to use and is the default setup in most configurations.

Here’s some examples of how to use error_reporting within the various files:

php.ini
error_reporting = E_ALL & ~E_NOTICE
.htaccess
php_value error_reporting E_ALL & ~E_NOTICE
Inside a PHP script
ini_set('error_reporting', 'E_ALL & ~E_NOTICE');
E_ALL & ~E_NOTICE

If you would like to display the errors to the users you should also add the following line in the same way as above:

display_errors On / php_value display_errors 1 / ini_set('display_errors', '1');

If you would prefer to just log the errors to a file and not display anything on screen just set the above to 0 instead of 1, then add the following directive in the same way as above:

log_errors 1 / php_value log_errors 1 / ini_set('log_errors', '1');

The errors will be stored in your servers Apache error log.

.htaccess file not being parsed/read

Posted by | Posted in Tutorials | Posted on 14-10-2009

Tagged Under : , ,

If you have a .htaccess file in your web directory and it does not appear to be being parsed, here’s a few things to check:

  1. Check the syntax of your .htaccess. Try commenting out using # line by line to see if you can get any part of it working.
  2. Check you’re using the Apache server. IIS does not work with htaccess!
  3. In the httpd.conf (normally located in /etc/httpd/conf/httpd.conf), check that the line AccessFileName is not commented out and make sure it is set to .htaccess.
  4. Also in httpd.conf do a search for AllowOverride and ensure that it is not commented out and that it is set to All for the directory root you are working in.

I hope this helps!