|
This last Thursday night I had the pleasure of giving a presentation to Indianapolis
.NET Developers Association (IndyNDA). First and foremost I would like to
thank the leaders, members and guests from the group. It was an enthusiastic
crowd that had lots of good questions and ideas to share. You guys totally rock:
The presentation
I came up with the idea for the presentation when Brad Jones, the President of the
user group asked me in an e-mail a couple of weeks ago "What are you going to talk
about?". I thought about some of the topics that have been "hot" lately.
Programming against the Facebook has come up
a lot lately. I showed a demo of a Facebook application at the last round of ArcReady programs. Dave
Bost and I just published an episode of The
Thirsty Developer on the Facebook
Developer Toolkit. So I thought about putting together a presentation about
how to tap into the various APIs that exist out on the Internet. Facebook, Flickr and Twitter are
my favorite social networks and all of them have very rich APIs. I thought I
would also throw in a little Virtual
Earth action to round it out.
The Code
I showed a couple of examples during the presentation. The first sample, which
was tapping into the Virtual Earth
APIs using the JavaScript. The sample was pretty basic, and it was meant to show
how quickly you could add a map to your site:
To setup a map like this you need to reference the JavaScript file on the live.com
website. You also need to setup a <div> tag that is the target of the
map. In the body tag of the HTML. Call a function, in my case it was GetMap().
The rest of the work is done with the following JavaScript which loads the map, adds
the pushpins from an array using a JavaScript prototype object.
<script type="text/javascript" src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=5"></script>
<script type="text/javascript">
var map = null;
//prototype object
function event(name,location,date,lat,lon)
{
this.name=name
this.location=location
this.date=date
this.lat=lat
this.lon=lon
}
//An array of event objects (would come from a web service or database
call)
var Events = new Array(
new event("IndyNDA
Meeting", "Indianapolis, IN", "2/10/2008", 39.889504,-86.121899),
new event("Devcares",
"Carmel, IN", "8/30/2007", 39.927089,-86.1516),
new event("ArcReady",
"Carmel, IN", "2/21/2008", 39.927089,-86.1516),
new event("MSDN
Event", "Indianapolis, IN", "2/7/1008", 39.927087, -86.025579)
);
// Loads the map and sets
the center
function GetMap()
{
map = new VEMap('myMap');
map.LoadMap();
AddEvents();
// uncoment the next line to Zoom in on
Indy and center the map there
map.SetCenterAndZoom(new VELatLong(39.889504,-86.121899),
11);
}
// function to add the individual
events to the map
function AddEvents()
{
for (i in Events)
{
var shape = new
VEShape(VEShapeType.Pushpin, new VELatLong(Events[i].lat,Events[i].lon))
shape.SetTitle(Events[i].name)
shape.SetDescription(Events[i].location)
map.AddShape(shape)
}
}
</script>
This code snippet is provided under the Microsoft
Permissive License
The HTML page it included in a zip file on this blog entry, it to is distributed under
the Microsoft
Permissive License. The permissive license is an OSI approved shared source
license. It does not require you to share your source code with anyone, but
if you do something cool building on this sample, please considering sharing it with
others.
I will do a walk through of the Silverlight Interface to Virtual Earth in a forthcoming
blog post.
VESample.zip (1.02 KB)
|