Friday, February 26, 2010

Developing with Online Mapping APIs - Part 1: Displaying a Map

The very first objective is to be able to display a map on a web page. There are just a few basic things we need in order to make this happen:
  • A reference to the mapping API
  • An HTML element to display the map in
  • A bit of script to initialize the map
To start, let's write a simple HTML page that will display our map.
<HTML>
<HEAD>
</HEAD>
<BODY>
<DIV id="mapDiv" style="position:relative;width:640px;height:480px"></DIV>
</BODY>
</HTML>

Nothing particularly fancy here. We've created a page with a single DIV that will be the display area for our map. There are no size restrictions on the map, but you'll want to pick something that fits well with your page design.

Next we need to add a reference to the script that will allow us to create and interact with maps. We also need a bit of custom script to create the map and set the initial display. The method for doing this is largely similar across APIs, but we will look at them individually in the following sections to highlight the differences in each.

Bing

To embed a Bing map on your page the first thing you will need to add is the reference to the Bing map JavaScript API.
<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"></script>

The only item of interest in the script reference is the v=6.2. This indicates the version of the mapping API that your code would prefer to use. This can be useful if there is a API change resulting in behavior that breaks your interface. Next, we need to add a bit of code to initialize our map. We will want to create a global variable to hold a reference to our map object. For this example, we will initialize the map on the page's onload event. There are two steps to initializing the map. The first step is to create the map object. The second step is to load the map content centered on a location.

<HTML>
<HEAD>
<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"></script>
<SCRIPT>
var bingMap;
function bingInitializer()
{
bingMap = new VEMap('mapDiv');
bingMap.LoadMap(new VELatLong(39.768519, -86.158041), 13);
}
</SCRIPT>
</HEAD>
<BODY onload="bingInitializer()">
<DIV id="mapDiv" style="position:relative;width:640px;height:480px"></DIV>
</BODY>
</HTML>

The constructor for the VEMap takes the HTML element that will host the map as an argument. The LoadMap method requires a lattitude and longitude for centering the map, as well as a zoom level. Unfortunately there is no standard for zoom levels across all APIs. In the case of Bing, the smaller the number the farther out the camera view. The greater the number the closer in the view. When developing a page that will host a Bing map, be absolutely certain that the 'position:relative' style is set on the HTML element the map will be displayed within. If this style attribute is missing the Bing map will overflow beyond the bounds of the DIV in the Google Chrome and Mozilla Firefox browsers.

Google

To embed a Google map on your page the first thing you will need to add is the reference to the Google map JavaScript API.

<script type="text/javascript" src="http://maps.google.com/maps?file=api&v=2&key=abcdefg&sensor=false"></script>

There are a few new items here. Again, we have a version refere (v=2) but now we also see a key parameter. Your site must register with Google to obtain a key for using the API. Failing to do so will result in a pop-up nag on your page. The advantage of registering for a key is that it eliminates the pop-up nag, and if you decide to purchase the support, will allow access to additional calls and features. The sensor parameter is used for enabling location aware services on mobile devices. We will leave this off for now, but I may cover it a bit in a future post.

As with the Bing map, we need to write a bit of script to initialize our Google map. We will create a global variable to hold reference to the map. Just like the Bing script, the Google script needs to both create the map object and then load the map content centered on a location and zoom level.

<HTML>
<HEAD>
<SCRIPT type="text/javascript" src="http://maps.google.com/maps?file=api&v=2&key=abcdefg&sensor=false"></SCRIPT>
<SCRIPT>
var googleMap;
function googleInitializer()
{
googleMap = new GMap2(document.getElementById("mapDiv"));
googleMap.setCenter(new GLatLng(39.768519, -86.158041), 13);
}
</SCRIPT>
</HEAD>
<BODY onload="googleInitializer()">
<DIV id="mapDiv" style="position:relative;width:640px;height:480px"></DIV>
</BODY>
</HTML>

Of note here is that, while the constructor for the Google Map object (GMap2) takes the HTML element that will host the map as the argument, you must get a reference to the element rather than supplying only the element ID. The zoom level value for Google Maps works just like Bing maps.

Yahoo

To embed a Yahoo map on your page the first thing you will need to add is the reference to the Yahoo map JavaScript API.

<script type="text/javascript" src="http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=YD-eQRpTl0_JX2E95l_xAFs5UwZUlNQhhn7lj1H"></script>

Here again we see a version number (v=3.8) and a application ID.

No surprises when writing script to initialize the Yahoo map.

<HTML>
<HEAD>
<SCRIPT type="text/javascript" src="http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=YD-eQRpTl0_JX2E95l_xAFs5UwZUlNQhhn7lj1H"></SCRIPT>
<SCRIPT>
var yahooMap;
function yahooInitializer()
{
yahooMap = new YMap(document.getElementById('mapDiv'));
yahooMap.drawZoomAndCenter(new YGeoPoint(39.768519, -86.158041), 5);
}
</SCRIPT>
</HEAD>
<BODY onload="yahooInitializer()">
<DIV id="mapDiv" style="position:relative;width:640;height:480"></DIV>
</BODY>
</HTML>

The only difference to note between the Yahoo map and the other mapping APIs is that the zoom value is reversed. Lower numbers mean closer to the ground while higher numbers mean farther away. One interesting quirk: the yahoo scripts for displaying a map use a global JavaScript variable 'i'. This is a common counting variable, and I'm guessing a bug on Yahoo's part. In any case, if you are using 'i' as a variable in the same code that is loading a map, you are highly advised to rename the variable to something more descriptive lest you find the Yahoo code has given it a new and unexpected value.

MapQuest

To embed a MapQuest map on your page the first thing you will need to add is the reference to the MapQuest map JavaScript API.

<script type="text/javascript" src="http://btilelog.access.mapquest.com/tilelog/transaction?transaction=script&key=mjtd%7Clu6t2h07n1%2C2x%3Do5-lw7l9&itk=true&v=5.3.s&ipkg=controls1,traffic&ipr=false"></script>

Again we see a key parameter (key=) and a version number parameter (v=). There are a few new players here though. The itk parameter is needed to include the Tile Map Toolkit in the scripts. Make sure this is part of the include string, and always set to true. The ipkg paramter indicates which features of the map are available to the user. Make sure this includes the controls1 value at a minimum. The ipr parameter is to indicate if you are using the premium features of the API (true) or the free version (false).

<HTML>
<HEAD>
<SCRIPT type="text/javascript" src="http://btilelog.access.mapquest.com/tilelog/transaction?transaction=script&key=mjtd%7Clu6t2h07n1%2C2x%3Do5-lw7l9&itk=true&v=5.3.s&ipkg=controls1,traffic&ipr=false"></SCRIPT>
<SCRIPT>
var mapquestMap;
function mapquestInitializer()
{
mapquestMap = new MQA.TileMap(document.getElementById('mapDiv'));
mapquestMap.setCenter(new MQA.LatLng(39.768519, -86.158041), 10);
}
</SCRIPT>
</HEAD>
<BODY onload="mapquestInitializer()">
<DIV id="mapDiv" style="position:relative;width:640px;height:480px"></DIV>
</BODY>
</HTML>

The MapQuest map zoom values are like the Bing and Google maps (bigger number is closer in) but the values do not correlate one to one like the Bing and Google maps do. A couple of notes are in order with regard to the dimensions of the DIV used for displaying the MapQuest map. First, the MapQuest API will not honor percentages when used for the map dimensions. If you try to create a map with an in-line style of 100% for height and width you will find the map actually displayed at 100 pixels by 100 pixels. Second, the MapQuest map API seems to have an issue with cascading style sheets. If the DIV that is hosting your map gets the height and width set from CSS rather than an inline style attribute the API may apply the height dimension to both height and width. This bug may be addressed in the future, but at present be sure to specify the height and width values inline with the DIV tag.

Is That It?

Getting the map on the page is just the start, and in the coming posts I will show you how to do some more interesting things with the map, such as displaying a point of interest and getting a lattitude and longitude value for an address. Until then, if you would like to read more about each API you can check out the following resources.

Developing with Online Map APIs

I'm planning to give a talk providing a basic introduction to the use of online mapping APIs. I plan to cover the big four: AOL (MapQuest), Google, Microsoft (Bing nee Virtual Earth), and Yahoo. The goal of the talk is to whet the appetite of site developers with the ease of putting a map on their site, and how valuable that map can be. I also hope to demonstrate where one mapping system provides particular advantages or disadvantages.
To kick things off, a bit of trivia: what is the most popular website for travel (and thus mapping)? If you said Google, you were right, but that has only been true for a few months. As recently as 2009 MapQuest had the crown as the number one portal for travel. HitWise has published their report for January 2010, and there you can see that Google Maps has opened a commanding lead. Travel is a pretty broad topic though, and we're talking about mapping. I've chosen AOL, Google, Microsoft, and Yahoo for this discussion as they are the most popular services offering a public API to their mapping technology.
Over the course of the next few weeks I will provide a series of posts covering the following mapping tasks:
  • Displaying a map on a page
  • Adding controls to the map
  • Adding points of interest to the map
  • Geocoding and Reverse Geocoding
  • Map events
  • Unique features to each API
I hope that this series is informative and useful.

Tuesday, December 8, 2009

HP Mini 1000 - Upgrading the Transcend JetFlash T3

A while back I posted about the HP Mini 1000 and some of the ways it can be upgraded. Probably the easiest upgrade is to the Transcend JetFlash T3 drive that comes with the machine, and fills the recessed USB slot. The Mini comes with a 2GB drive, and the easiest upgrade is to simply purchase a higher capacity Transcend drive in the same line. The 4GB unit is priced at $16.70 on the Transcend store website, or $16.29 from Amazon.

I found a neat alternative. Kingston offers a MicroSDHC card that comes with a MicroSDHC card reader whose form factor is very similar to that of the JetFlash T3. The 4GB card with reader is priced at $14.95 through Amazon currently. I wanted to upgrade the MicroSD card in my GPSr anyway, so this seemed like a good opportunity to try it out.

The first thing I noticed when I got the package was that the MicroSDHC reader is about 20% shorter than the Transcend card. Aside from that, the form factor was perfect. I slotted the 4GB MicroSDHC card into the reader, and then slide it into the small holder that covers the recessed USB port on the Mini. I slid everything into place, but nothing happened. Unfortunately, the shorter length means that the pads don't quite reach to make a connection to the USB port. All is not lost though. With a bit of fiddling, I found I could get the reader to slot into the recessed port without any issue. At that point, I can leave the cover on or off, it doesn't really matter, as the reader is completely within the recessed slot. If you do want to keep the cover on, be sure to slot the reader into the cover first, as trying to push the cover on over the reader after it has been slotted is a chore. Getting the reader back out again is a bit of a trick, but nothing you couldn't do with a handy set of tweezers, or a small set of needle nose pliers.

Given the lower price of MicroSDHC card and reader at the same capacity, I think this is a pretty good way to upgrade your machine. Another advantage is that, as MicroSDHC card capacities increase and prices drop you can continue to upgrade this part.

Friday, September 4, 2009

Rural Internet

My family and I are preparing to move out of the city and into a more rural setting. As part of that move, I've been researching what sorts of internet service will be available to us. At our current residence we have a number of different options for high speed internet service. We currently use the U-Verse service offered by AT&T. We are using the 1.5Mbps service, which adds $15 / month in cost to our U-Verse television bill. Comcast also offers high speed internet service, and I'm sure we could get DSL from any number of folks. Go a few miles outside of a dense residential area and your options quickly become limited.

There are four types of service that I have found that will be available at our new location:
  • Dial-Up
  • Satellite
  • Cellular Wireless
  • Microwave Wireless
Dial-Up
Dial-up internet service is the old standby that hasn't changed in over 10 years. The top speed is still pegged at 56kbps (ignoring the "speed boosting" tech that some vendors claim). Depending on the service provider, rates run anywhere from $10-$20 / month. However, we don't plan on having a home phone, so add to this cost the price to install a home phone (around $25 / month with AT&T) for the sole purpose of using dial-up, and it comes to $35 or more per month for that sluggish dial-up internet connection. It would be useful for the most basic internet uses: browsing basic web pages and sending e-mail. Forget about online gaming or rich web media though. Compare this to our U-Verse service, which is the equivalent of 1,500kbps for $20 less each month, and it would be a serious step backward.

Satellite
There are a few satellite internet providers, Hughes and WildBlue being the most prominent. Hughes offers 1.0Mbps down, 128kbps up service for $60 / month, while WildBlue tiers their service at 512K down / 128K up for $50, or 1.5M down / 256K up for $80. Those are fine speeds, if a little pricey. The real gotcha here is latency. It used to be that with satellite internet you only received data over the dish, and all of your uploads were on your telephone line. Now you get both your up and down data from the dish, but the latency can be anywhere up to 5 seconds. Compare that to the typical sub 0.1 second latency of other internet connections, and it is a big downer. This makes the satellite internet service unusable for things like voice chat, VPN connection for working at home, or online gaming. Using a VPN connection and online gaming are high priorities for me from my internet connection, so that eliminated satellite from contention.

Cellular Wireless
Cell phone companies offer data plans for their users who have smart phones (Blackberry, iPhone, Android, etc.). This offers a fairly speedy (348kbps or faster) way to access the internet. Most carriers offer mobile broadband service with the intention that you use it occasionally with your laptop, not as your dedicated home connection. Across providers, the standard seems to be to offer up to 5GB of downloads per month for $60 / month. That may seem like a lot, but it really isn't when it is your dedicated connection for home. You can quickly exhaust that 5GB quota and start paying exorbitant rates per additional kilobyte downloaded. For example, let's say a new product revision is released, and the download is 1GB or more. If there are alternate versions, I could exhaust all 5GB in a single afternoon. The idea of these caps is to prevent folks from hogging the network with P2P applications, swapping movies all day, and to keep usage as intended: occasional use on a mobile device. The net effect for me is that cellular is not an option as a home ISP.

Microwave Wireless
I found microwave wireless service to be the best mix of speeds, price, and availability. There are several service providers that can provide service to our location. With microwave wireless you need line-of-sight to the tower providing the signal. A small antenna is mounted on your home and communicates wirelessly with the main tower. Depending on geography and tree line, these systems can offer service in a 15-30 mile radius around a tower. Prices vary by speed, with it ranging from $35 / month for 512K down, 256 up service to $90 / month for speeds over 1Mbps. There isn't a single dominant player in this market like there is in the national cellular market. The best deals I found were offered by a local company: Hoosier Broadband.

512K/256 $34.95 Residential Service
768K/384 $44.95 Residential Service
1.5M/512 $69.95 Residential Service
512K/256 $54.95 Business Service
768K/384 $64.95 Business Service

The difference between residential service and business service is that Hoosier Broadband reserves the right to lower the priority of residential traffic in deference to their business customers, and business customers are guaranteed support within 24 hours. Residential customers are not. I'm not yet decided on whether I would choose the business or residential service. As the majority of my usage is late at night, I think the residential service should suffice, but given that I also intend to use this service when I need to work from home, the business service might be more prudent. Either way, I would be selecting the 768K service, which is half of what we get now from AT&T. A cut back, yes, but not a terrible one.

DSL, FiOS, and ISDN
Just a quick note on these services: they aren't available. In fact, you probably can't remember the last time (or ever) hearing about ISDN. When I contacted the phone company, they said they are not selling new connections, but only maintaining existing accounts. That's fine, as ISDN has all of the drawbacks of dial-up with a higher cost and only barely better speeds. FiOS would be awesome, but there's no chance of getting that in a rural area as it is too expensive for Verizon to pull new fiber down country roads for a handful of customers. Maybe someday DSL will be an option, but not now.

Summary
I think that microwave wireless is one service that we will hear a lot about in the coming years. One of the president's major policy initiatives is to increase access to broadband internet service for rural Americans. Installing a tower for wireless transmission is one of the most cost effective ways to do that, and the FCC is in active talks concerning opening up more of our wireless spectrum for data traffic (this is a major reason why we had the recent switch from analog to digital television over the air). I'm hopeful that these changes will result in more options for me as rural internet consumer, and lower prices.

Tuesday, July 21, 2009

HP Mini 1000 Internal Microphone on WIndows 7

One of the only complaints I had about my HP Mini 1000 netbook when I purchased it was the lack of a dedicated microphone jack. The Mini has a combined headphone/microphone jack. You can plug in a set of headphones and get sound, or plug in a mic and record, but not both at once. I like to use Skype, ooVoo, Ventrillo, and other voice applications, and this seemed like an unnecessary limitation.

After loading up Windows 7 on my netbook, I was further disappointed to find that the default driver did not detect if you plugged in a mic or headphone, it just always worked as a headphone jack. This left me with no option for recording other than to use a plantronics USB headset that I had laying around. Taking up one of two USB ports for a headset was less than ideal.

Then I read on a forum that the Mini has an internal microphone. What's this? Hidden, undocumented equipment? Sure enough, half-way between the left edge of the screen and the webcam there is a pinhole microphone. Unfortunately, I couldn't find a way to enable. I did see it was listed in my recording devices, but I couldn't get it to pick up sound.

After a bit of searching, I found a link to a driver for the sound chip in the Mini 1000:


I believe this is the official vista driver for the sound chip. After downloading and installing I went to the recording devices menu and sure enough, it is picking up sound! Yeah! The only quirk is that it appears the labels for the recording devices are switched. The recording device marked as External Mic is picking up sound, while the recording device marked Integrated Microphone Array is not. I just switched the default device and now I can carry on Skype video calls without any problems.

Tuesday, May 5, 2009

HP Mini 1000 Upgrades

Own an HP Mini 1000, or looking to buy one, and want to know what parts can be upgraded?  I've been poking around to see what is available for this great little netbook, and here are some of the things I've found.

Memory
The Mini comes with either 512MB or 1GB of memory.  This is definitely the easiest part to upgrade.  The documentation seems to suggest that 1GB is the max for this device, but mine took a 2GB Kingston DDR2 chip without any complaints.

Hard Drive
The hard drive is a bit trickier.  You'll need to take the keyboard off to get access to it.  If you have a unit with a SSD, you'll also need to disconnect the recessed third USB port.  There is a good demonstration of how to do all of this here: http://jkkmobile.blogspot.com/2009/01/runcore-18-inch-ssd-on-hp-mini-1000.html

HP Mini Drive
If you purchased with the SSD option, you probably received a 2GB "HP Mini Drive".  This is actually just a Transcend JetFlash T3 with a small plastic piece to help it blend nicely with the body of the netbook.  You could either order a larger unit from HP, or you could get an original Transcend unit.  As of this writing HP is selling the 4GB for $24.99, while transcend has the same unit priced at $17.60.  Transcend also offers an 8GB drive for $32.30, which HP does not currently offer.

WWAN
There has been a lot of chatter lately about cellular carriers offering discounted netbooks on a 2-year data contract.  The HP Mini 1000 is poised to be a part of that offering.  If you ordered yours with the WWAN card built in, you are already set.  If not, you can still add one later.  This video from jkkmobile demonstrates how to add a WWAN module to your netbook.  Again, this involves taking off the keyboard and doing some pretty serious tinkering, so it isn't recommended for the faint of heart.

Battery
The stock 3-cell battery will net you anywhere from 1 to 3 of continuous use, depending on your power settings and what you are doing.  HP now offers a 6-cell replacement battery, available for order here.

External VGA
This one is a stickler.  That funky connector on the left of the unit is where you plug in a propietary VGA adapter cable.  Unfortunately, these are both in short supply and full of issues.   Users who have the cable are reporting that it refuses to output anything but 1024x768 regardless of what display is attached.  This is bad news for anyone hoping to connect to a projector.

I love my netbook and I am getting a lot of great use from it.  It is running Windows 7 RC1 like a champ, and I'm even able to do a little development in Visual Studio on it.  So far I have only upgraded the memory, but I'm tempted to upgrade the Transcend flash drive.  I'm holding off on a SSD upgrade until prices come down, but it is tempting as I currently only have about 1.5GB of free space on the main drive.  Even with a relatively "stock" configuration, I find this unit to be a very nice, performant, and portable computing platform.

Friday, April 24, 2009

Netbook, Windows 7, and Ubuntu Netbook Remix

A couple of weeks ago I picked up a HP Mini 1000 netbook.  I had a couple of intentions for this netbook.  Firstly, I wanted to use it for any personal network use wherever I went.  Rather than using my work PC for checking account balances, personal e-mail, and other non-work related network uses, I would use the netbook instead.  Second, I wanted a portable machine that I could do some light development on.  Nothing complicated mind you, but just the ability to open up a small project, hack some code, and check that it compiles.

After playing around with the netbook for a while, I can safely say that I am very happy with the decision to purchase it.  Netbooks are the latest consumer trend in computing, and there are a lot of models out there.  You'll find that they are all very, very similar.  The typical unit has two or three USB ports, a 1.6GHz Intel Atom processor, 512MB or 1GB or RAM, and a small solid state hard drive, or possibly a traditional magnetic drive.  Most come bundled with a simplified Linux operating system, or Windows XP for a slight price premium.  With so many vendors and so little to differentiate them it can be difficult to settle on one.  I chose the HP model mostly because the keyboard felt the most comfortable to type on.  Otherwise, there isn't much to differentiate it from the other $350 10" netbooks on the market.

I made some modifications to my netbook before even powering it on.  First, I upgraded the RAM to 2GB, which only cost $20.  Next, rather than use the provided Windows XP operating system I decided to load the beta of Windows 7 (with some help from my colleague Mike Hall who had done the exact same thing to his own netbook).  I loaded Visual Studio 2008, Google Chrome, and a handful of utilities that I like.  After install my 16GB SSD has about 1.5GB of remaining free space.  I put all of my code on the provided 2GB "HP Mini Drive", and I still have two USB ports and an SD Card slot to expand memory further, if necessary.

I'm very happy with Windows 7.  Even on the relatively weak processing power of the netbook it runs like a champ.  I definitely like it as a replacement for Windows XP.  Visual Studio runs well, if a bit sluggishly, and I am able to compile projects as I had hoped.

Still, this beta is eventually going to run out, and at that time I need to make a decision between paying for a license for Windows 7 (if it is available) or selecting some other operating system.  I could always revert to Windows XP, which came with the unit, at no cost.  Or I could try one of the linux variants on the market, also at no or little cost.  A friend of mine tipped me off to the Netbook Remix of Ubuntu.  Version 9.04 of the Linux OS just released, so I decided to download it and give it a try.  One of the nice features of this release is that you can try it by loading it on a USB stick as a "live" OS, which means you can run it without wiping out the OS already on the machine.

After playing with the netbook remix for a bit, I was impressed.  I'm not ready to swap out my Win7 install, but when the beta expires it will definitely be something I consider.  With MonoDevelop 2.0 and the Mono framework running I could probably still do some light C# work.  One feature of the OS that I really liked was how UI works to maximize screen real estate for the foreground application.  One of my frustrations with running Chrome (or any other browser) on Windows 7 is how much of my precious screen is taken up by title bars, menu bars, toolbars, bookmark bars, status bars, and task bars.  With limited vertical space, it leaves only just enough room for my active application.  This is exacerbated by sites like Google Reader that have a static header that cannot be minimized.

In summary, I'm very happy with the utility I am getting out of my netbook, and I think Windows 7 is a solid OS choice for the platform.  I'm impressed by what I see in Ubuntu Netbook Remix as well, and I may give it a try when my beta license expires.