Geocoding... Virtual Earth + Google Maps

Posted by John
on Monday, 29 October 2007

As most will know but some still contend against, the world is indeed round; and to track a point within said world we use a system of Latitude and Longitude; and maybe the odd Harrison watch.

Now for computer's it's a little more complex. System's like Google Earth and Virtual Earth use something called Geocodes.

Unlike Latitude and Longitude which operate with hours, minutes, seconds; Geocodes are point-mapped numerically to the location.

Now converting zipcodes to geocodes is simple but I've been looking around and apparently UK postcode -> geocodes aren't freely available due to Royal Mail wanting cash, but I may be wrong.

Here's some resources to get you started...

Links

Virtual Earth SDK

Nice VS.NET example

Pricey for the UK, supposedly

Google Maps API Blog

Google Maps Clickable Polys

Geocoding with Virtual Earth & Google Maps

Precise Map Pointing with Virtual Earth

OpenStreetMap

Finding things with Virtual Earth

Reading points and plotting with Virtual Earth

link + demo

Source...

Feeding Maps with GeoRSS

code breakdown

hurricane tracker

Geocoding Tools

ASP.NET Guides

Posted by John
on Thursday, 25 October 2007

While hunting around for a new ASP.NET AJAX book I ran into these two excellent posts.

Good stuff, well done guys!

C# Crib Sheet

Posted by John
on Sunday, 05 August 2007

string b = @"hello
p. stuff"

@ means string must be displayed like written, on two lines


Arithmetic Overflow

checked(b2)
p. unchecked(b2)

checked = means expression ‘b2’ value does not exceed type


b2?

+++b2 b2+++

>= <= == != ++

end lines with ;


if (b2 == b3)

{ code }

else if (b2 > b3)

{ code }


switch(x) {

case 1:

——;

break;

default:

——;

break;

}


while (b2 = 2) { b2++; }


do i++ while (i<5);


for (int i=0l i<0 i++) { }


foreach (Stick stick in dynamite) { stick++; }


return b2;

return = return value / object to calling code;


namespace mycompany.myproduct.drawing { }

namespace = enables you to group related types into a hierarchical categorization


inheritance

class URL : Location { // }

: <= allows URL to inherit the methods of the Location class


polymorphism = ability to perform same operation on many types

virtual function members = each type can implement a shared characteristic in it’s own way. implements shared characteristic / method in it’s own way


abstract class = shell of a class, no implementation, cannot use directly, have inherit / build upon

abstract class Location { public abstract void Launch(); }

class URL : Location { public override void Launch() {} }

override = override inherited classes methods, in this example i’m using an abstract class as a sort of template for something new


public new void Foo() {}

new = hides method from outside class


public = type / members fully accessible

internal = type / members accessible only from within

private = type / member accessible only from within

protected = cannot modify, class available within class


difference between classes & structs ?

class = fully supports inheritance, reference types, can have destructor, can have custom parameterless constructor

struct = simple, value types, can have constructor


instance = (default), associated with an instance of a type

static = associated with a type itself

public static void Me() { }


public const double PI = 3.141

const = constant, always uppercase


ref = pass by reference, change value of variable given permanently

static void Foo(ref int p) { ++p; }


params = allows method to accept any number of parameters

static int Add(params int[] iarr) { foreach (int i in iarr) {…} }


constructor = specify how new instances of a class get created, what variables get initialised with, etc.

class wow { public wow() : this(5) {}

make method same name as class to do this, here we’re self-referencing the class using the ‘this’ keyword, returning 5 to the calling class

static constructors = can define only one static constructor


destructor = specify how instances of a class get destroyed, connections get closed, etc.

class wow { ~wow() { console.writeline(“boom”); } }

~ defines a destructor, plus make it the same name as the class, here writing ‘boom’ to the console when the class is destroyed


this = self-referencing, denotes a variable that is a reference to a instance, allows members to reference own class

public dude(string name) { this.name = name; }
p. public void hi(dude a) { if a!=this) {..} }

a common use of ‘this’ is to unambiguate a field name from a parameter name.

e.g. = self-reference the current class instance

JAVA

  1. class Numbers {
  2. private int aNumber = 42;
  3. public int returnANumber()
  4. {
  5. return this.aNumber;
  6. }
  7. public int returnANumber(int intIn)
  8. {
  9. return (intIn * this.returnANumber());
  10. }
    #
  11. public static void main(String[] args) {
    #
  12. Numbers numberTest = new Numbers();
  13. System.out.println("The Number is " +
  14. numberTest.returnANumber() );
  15. //output is: The Number is 42
  16. System.out.println("The Number is " +
  17. numberTest.returnANumber(2) );
  18. //output is: The Number is 84
  19. }
  20. }

see how the above example works, a variable is defined inside the class, a method is defined for when no parameters are given assigning it 42. when parameters are given it runs a different method multiplying 42 with the number given. however it’s referencing (can modify directly & permanetly) the value inside it’s own class.

also in JAVA,
p. super.getName(a); = use super. to call methods in the parent class


base = similar to ‘this’, except that it accesses overridden or hidden base-class function members

basically allows you to call the original function of a class before it got replaced by one with the same name / overridden

base.Introduce(p);


interfaces = like a pure abstract class, but provides a spec rather than implementation of it’s members

public interface Me { void Delete(); }

here no code is written, just a function is defined, which when inherited by another class (using : ) can then be coded.

basically a template class, an empty shell


arrays

char[] vowels = new char[] (‘a’, ‘e’);
p. console.writeline(vowels[ 2 ]);

multidimensional arrays

int [][][] matrix = new int 3[][];
p. matrix[x][y][z] = new int 5;

= vowels.Length;
= matrix.GetLength(2)


enums = specify a group of named numeric constants


events

get { return pos; }
set { r = 44; }


try { }
p. catch { }

finally { }

basically you try something risky, you catch any error codes and then you finally clear up your mess


ArrayList = dynamically sized array of objects that implement the IList interface

HashTable = standard dictionary layout (key/value)


StringBuilder class

can grow unbound or upto a pre-defined maximum, much better than just concatenating a string.

it starts at a pre-defined size and grows dynamically as more string data is added.

StringBuilder sb = new StringBuilder(‘hello ’);

sb.Append(’world’);

sb12 = ‘!’;

console.writeline(sb); // hello world


// = comments

DNS Mastery + Google Apps

Posted by John
on Sunday, 29 July 2007

DNS = Domain Naming Service
p. …quite simply the glue that ties your newly purchased .com to your server’s hardware.

There’s a few other bits to it, like the Name Server, or the original Domain Name Registrar (e.g. godaddy.com); they’re a little more involved but I’ll try to cover them here.

Buying your Domain Name

First off, go buy your new domain name at one of the domain name registrars. I’ve suggested godaddy.com purely because they’re so cheap, but you can use any other.

Next once you’ve bought your domain name, go in and you’ll be able to point it to a naming server. This connects your .com to the server containing your dns details and thus to your meat & potatoes server box.

So for this example, we’ll use SliceHost (although you can use the free DNS provider FreeDNS who provide the service free of charge, I’ve used and are really good.

Go to your DNS provider and they’ll provide you with a list of nameservers you can use.

e.g.
bq. ns1.slicehost.net
ns2.slicehost.net
ns3.slicehost.net

Go to your domain registrar and in the nameserver provider part, enter these three (3 for automatic failover, one fails the other takes charge, etc.).

Creating your DNS records

Now we’ve got the .com pointed to the DNS provider that will host our DNS records, let’s go create some.

So, for SliceHost, go to the DNS Records section, click ‘advanced view’ (specifically for slicehost); and now We’ll begin.

Create a record for each one of these

type: A

name: www

data: (ip address of your serverbox)

type: A

name: mysite.com.

data: (ip address of your serverbox)

Note the . at the end of the one above (DNS records always have a fullstop at the end), and that it doesn’t have www. at the start.

Next we need to tie the domain name to the name server for a sort-of reverse lookup. So create records like…

type: NS

name: mysite.com.

data: ns1.slicehost.net.

type: NS

name: mysite.com.

data: ns2.slicehost.net.

type: NS

name: mysite.com.

data: ns3.slicehost.net.

Notice the fullstop at the end of the Name and Data part.

Unfortunately now we have to wait for these settings to propogate thru the web, can take up-to 48 hours but usually quicker (try doing this at midnight in the UK).

Using Google Apps for your Email

Now we’ve got the site hooked up to the server box, how about email?. Well, you could install an exchange mail server on your box but they’re usually a nightmare for the beginners; so how about we use Google Apps & GMail?.

Google Apps is a new free service google has launched to provide home users and small business with a way of having standard google tools but tied to their domain name. So you can have john@mysite.com be your email address but use Google GMail to handle it without building an exchange server; big headache gone.

Go to the Google Apps website and register for the free Standard service. Use your new domain name mysite.com and create an email account for it.

You’ll need to verify your site with Google to turn the service on, quickest method is to put an HTML file on your server’s /public web directory and click VERIFY.

Once done go back to SliceHost / Your DNS provider and create a new record,

type: MS

name: mysite.com.

data: ASPMX.L.GOOGLE.COM.

auxilary info: 1

..the 1 is the priority level, Google will probably tell you to create more of these but for now one will do.

Now once google shows your site as Verified all the services (calendar, excel, start page, etc.) will switch to Active. Setup your Email part and tell it you’ve done the MX record change and it’ll switch to Updating. Now wait 3-48 hours for it to check the MX record on your DNS provider.

If all ok, that’ll go to Active, send an email to the address to check and it should work.

Using shorter URLs for Google Apps

As you’ll have worked out, Google doesn’t give you the best web addresses to access your Google Apps email, docs, etc.

To make this more simple, go to each service in your Google Apps Dashboard and click ‘change url’, pick the one it gives you (usually mail.[mysite.com], etc. ) and click ok.

It will then tell you how to adjust your DNS settings appropriately, but to make this simpler, login to your DNS control panel in SliceHost (or whatever DNS service your using) and add some CNAME aliases.

type: CNAME

name: mail

data: GHS.GOOGLE.COM.

type: CNAME

name: start

data: GHS.GOOGLE.COM.

type: CNAME

name: docs

data: GHS.GOOGLE.COM.

type: CNAME

name: calendar

data: GHS.GOOGLE.COM.

CNAME records basically act like an alias pointing to your core domain. So adding a record with a name of ‘mail’ will suddenly redirect anything with mail.mysite.com to the location you put in data. Once done, it should take effect in 1-3 hours.

Final Points

A name records are much like CNAME records only they have a lesser performance impact, however if you are gonna create some more like blog.mysite.com I’d stick to CNAME’s; only create one A record for your www => www.mysite.com connection.

Drop me a line if you get stuck,

All the best,

John.

atompad signs up

Posted by John
on Wednesday, 04 July 2007

atompad.com

Well, after some tinkering with my ‘ns’ & ‘a’ records I soon managed to get the domain atompad.com resolved correctly and that left me with installing my signup app and setting up my server slice.

Thankfully most of the hard work for deployment of my rails app is carried out via Capistrano, allowing me to install PHP5, Mongrel, Ruby, Gems Framework, Rails, Blowfish, MySQL and Subversion, plus configure them all remotely.

Automated Installs with Capistrano

Now I finally have a Ruby on Rails app running in the wild and more importantly version controlled and on 64bit hardware with it’s own dedicated memory space.

The app itself isn’t that posh, it’s part of an idea I’ve had for a couple of years but never had the time to put it into practice but I guarantee you it’ll be fun, I posed the original idea to my mum to see if she’d find it useful and after a few minutes talking she couldn’t wait to signup!

www.atompad.com

Please Note, the signup part has only JUST gone live so try not to flame me if it all goes blue-screen; and before you ask, NO I will not be selling your details off to some nasty company; I have a heart after all.

…on holiday now, much deserved but i’ll try to answer your emails when I can, getting engaged!

till next time, take care all,

John.