Sunday, July 14, 2013

Adding A Google Map To Your Site Using Google Maps API

Recently I redesigned one of my old web sites (, and decided to add a few Google Maps on pages where address information was important. It was nice to see that this simply required a little bit of JavaScript to get up and running. Minimal effort is needed to add a simple map that will include a marker on a specified address.

Below is a simple example of how to setup your map using a provided street address. The Google Geocoding API makes it possible to use a street address instead of the standard GPS coordinates. This made my life a lot easier, as I already had street addresses stored in my database and did not also want to store the GPS coordinates.

To get started, head over to the Google API Console and get yourself an API key. Once you've done that, you can reference the Google API script using a script tag like the one below.

<script src=""></script>

After doing that, you can add your own JavaScript similar to the example below. Replace the address information with the street address that you would like to appear on the map. This can easily be fed from a database to make the maps dynamic. I am adding a marker that points to the address in this example, as well as centering the map to the specified address. If you don't want a marker, you can easily remove the code that references the marker variable.

One final thing that you will need to do is to add a container for your map. Mine is a div with an id of "google-map." As you can see, it is referenced in the JavaScript above, so you will need to update that if you use a different id.

You'll want to specify a size for your div container. Below is some example CSS for this. As you can see, I also surrounded it with a border and added a margin on the bottom.

All in all, adding a simple Google Map is quite painless. I found the Google API Tutorial at w3schools to be quite helpful in getting me on track with Google Maps development, so you may want to check that out if you'd like to delve into some of the many additional features that are available.

Tuesday, June 18, 2013

Forcing Internet Explorer to Automatically Launch a File Type

This week at work I was asked to get Internet Explorer to automatically launch a custom file type for an application that I am working on. I was able to do this manually with IE8 by clearing a checkbox that asked if I should always be prompted when opening the file type. Unfortunately, I could not find a similar option with IE9, which happens to be our target browser for this project.

Luckily, I stumbled across this post on the Microsoft forums, which provided a key registry entry that can be used to force IE9 to auto launch files of a given type upon download. The details of this entry are buried three pages deep in the responses, but it works like a charm. The registry key in question is this one:
You have to add a DWORD value that is named after the file type for which you want to auto launch downloaded files. The example given was AcroPDF.PDF.1, but I had to provide the key name associated with my file type under HKEY_CLASSES_ROOT (i.e. My.File.Type). After testing out the change manually and ensuring that it worked properly, I added some code to my .NET app to check for the existence of the registry value and create the registry value if it does not exist.

Below is an example of what this code would look like. Note that I am checking for null to see if the registry value is missing altogether.

Thursday, April 18, 2013

Giving Back to the Community

Many of us developers spend all day at the office writing code only to turn around and work on our own coding projects at home. Based on discussions with other developers, I know that I am not alone in being at a stage in my life where I have many more ideas for personal coding projects than I have time available to work on them. I suspect that this very scenario may keep many developers from giving of their time and talents within their community.

Giving back can come in several forms. A number of my friends have participated in area Give Camps, which is a sort of weekend long blitz where developers converge on a single location and knock out reasonably sized projects for local organizations. Another way that many give back is to give presentations at local user group meetings that are open to the public. Even if you aren't so keen on public speaking this groups often can use someone to do some of the behind the scenes work for their organization. Perhaps even better yet is to seek out an organization in your community whose cause you're passionate about. I've found that these organizations are often open to receiving development help, even when they are not publicly asking for it. Take it upon yourself to ask if they could use your services.

Not everyone may have time to meet with an organization face to face in order to serve. However, another trend that continues to be on the rise is to write open source applications and utilities. These can be of benefit both from the standpoint of an application's utility and from the standpoint of giving other developers the chance to learn from your code.

I have to give a tip of the cap to commercial software developers that have decided to generously release their legacy games and applications as freeware and/or open source software. I recently was the beneficiary of this, as I had just completed converting a JAMMA arcade cabinet to a MAME arcade cabinet, which now runs a number of arcade and console emulators on an old computer that I was no longer using. This was a great way to consolidate some of my old games into a single interface. It just so happened that I read a posting which talked about how Cinemaware had released all of its old games as freeware. Much to my delight, I found that they were so generous as to offer download links on their web sites for these classic games in many formats, including Nintendo, TurboGrafx, and Gameboy.

Chances are that I have only scratched the surface on the number of ways that developers can give back to their communities using the skills that they have honed in the workplace. If you haven't sought out such opportunities yet, make it a point to do so. I have to say that I have by and large enjoyed my experiences when programming for a cause, and I'm confident that you will to.

Tuesday, January 1, 2013

.NET 4.5 Behaviors

My company made the move to Visual Studio 2012 back in the fall. Since making the move and updating our projects to the .NET 4.5 framework, we had been noticing an error relating to behaviors when building our apps. The error was something along the lines of the following:

The type 'MyType' from assembly 'MyAssembly.Stuff' is built with an older version of the Blend SDK, and is not supported in a Windows Presentation Framework 4 project.

Despite seeing this error, we could still run the app successfully. However, this would also cause issues with loading the window in the XAML designer.

After some research, I found that there is a 4.5 version of System.Windows.Interactivity that needed to be referenced in order to fix the issue. This DLL comes as a part of the Blend + SketchFlow Preview for Visual Studio 2012. As the title indicates, this is a preview version, so we can expect the final version in the near future. According to Microsoft, the final release of this DLL will come as a part of Visual Studio 2012 Update 2.