Recent Blog Posts RSS
ViaWindowsLive on Via Virtual Earth Blog
The new ViaWindowsLive community site has launched and features not only a definitive set of resources on all Live Services from Microsoft but also a special section on Virtual Earth including a new site gallery for you to upload your sites, new articles on Version 6, including getting started guide, an interactive quick guide, location finder and more. Subscribe to the VWL aggregated blog to stay in touch with everything Live Services related. Find all the great content from this site and much, much more. Explore how other Live Services can compliment Virtual Earth and your applications.
Version 5 URL changed - Error: 'VEMap' is undefined on Via Virtual Earth Blog
It has been reported that the old url to access the Version5 javascript for Virtual Earth no longer works. This is effecting sites worldwide.
The correct way to reference the Version 5 javascript is:
<script type="text/javascript" src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=5"></script>
If you have been effected a forum thread has been started here
Silverlight Virtual Earth viewer on Via Virtual Earth Blog
With the launch of silverlight yesterday I was digging around and found this viewer for Virtual Earth by Greg Schechter. It does use the 1.1 alpha of silverlight. It gives some interesting ideas for where Virtual Earth could be headed. Certainly the demo of the performance of silverlight compared to javascript for processing showed a significant increase. This could be very useful.
And of course on the gamer front check this out by Andy Beaulieu and shoot down some UFO's over Birdseye images.
John.
So much new Virtual Earth Imagery Worldwide. on Via Virtual Earth Blog
I subscribe to all the VE blogs and recently the posts about updated imagery has been more and more frequent.
The latest is here and for myself downunder we saw three updates, Canberra, Newcastle and Uluru:


Derek Chan posts 3 Articles in a month! on Via Virtual Earth Blog
A big thank you to the efforts of Derek Chan who posted his third VE article today (he actually had it ready weeks ago but had to wait for Mr Bottleneck here at VVE ;) )
The 3 articles are all relivant to Version 5 of Virtual Earth and deal with the Mini Map, debugging javascript and now custom pins in routes.
All these can now be found in our articles section.
If you have something to contribute send us an email.
John (The bottleneck)
Building Your First Commercial Website using Virtual Earth RSS
This article is written for an old version of the Virtual Earth platform. While still available for reference purposes, it is unlikely to work if implemented.
In order to use Virtual Earth on a commercial website Microsoft has provided a special "commercialized" version of the MapControl. The idea behind this control is that Microsoft allows you to use the control for free but reserves the right to place advertising on the control. The advertising will come in the form of geographically relevant content based on the searches carried out by the user. An example page is shown below in figure 1. This example page can also be seen here: http://www.viavirtualearth.com/MyVirtualearth/MapSearchControl/Sample1.html

Figure 1 - Virtual Earth Commercial Control
The control for commercial use is very similar to the basic map control that is discussed in the article Creating Your First Virtual Earth Web Page. It is recommended that you read that article first so that you understand the essentials to getting the MapControl working.
The commercial MapControl is called VE_MapSearchControl. You can find a test page that shows the methods and events you can use here http://www.viavirtualearth.com/MyVirtualEarth/MapSearchcontrol/MapSearchcontrolTest.html
The main differences between the basic MapControl and the commercial MapSearchControl are:
- The MapSearchControl requires a Cascading Style Sheet
- The MapSearchControl contains built in search facilities. These do require some work to make them function correctly.
There are 2 files you will need to reference from the page that uses the MapSearchControl; VE_MapSearchControl.css and VE_MapSearchControl.js. These files can be found here:
- http://dev.virtualearth.net/commercial/v1/VE_MapSearchControl.css
- http://dev.virtualearth.net/commercial/v1/VE_MapSearchControl.js
To add a MapSeachControl to a web page you will need to import the cascading style sheet and the javascript file. Then you can call the Create method on the control to obtain a control instance. The first nine parameters are the same as the basic MapControl. The last two parameters point to the pages that will be used to carry out the 'what' and 'where' searches respectively. Notice these last two parameters are also relative paths to pages that are hosted on the same site as the page being displayed. This is important as it resolves the security risk of making cross domain calls.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Sample 1</title>
<link href="VE_MapSearchControl.css" type="text/css" rel="stylesheet"/>
<script src="VE_MapSearchControl.js">
</script>
</head>
<script>
var map = null;
function MyOnLoad()
{
map = VE_MapSearchControl.Create(
47.6, -122.33, 12, 'r', "absolute",
10, 10, 600, 500,
"What.aspx",
"Where.aspx");
document.getElementById("contents").appendChild(map.element);
}
</script>
<body onLoad="MyOnLoad()">
<div id="contents" style="font-size:10pt">
</div>
</body>
</html>
Implementing the searches on your server machine
In order to get the searches working on the control you will need to implement two pages on your server that act as proxies to the actual searches on the MSN site. The two searches are for are the ads (what) and the location (where).
In the article Taking the Search Server Side I describe how to use a server side ASP.NET page to call through to the MSN search page. You will need to do something similar to get the MapSearchControl to work.
Lets start with the location, or where, search.
First you need to create an ASP.NET page that has no content. Remove the entire HTML content apart from the Page directive on the first line.
<%@ Page language="c#" Codebehind="Where.aspx.cs" AutoEventWireup="false" Inherits="MyVirtualEarth.MapSearchControl.Where" %>
In the code behind page you can remove most of the namespace references, you will need to add a reference to the System.IO and System.Net namespaces.
using System;
using System.Web;
using System.Net;
using System.IO;
In the Page.Load handler we can check that there are some parameters passed into the page. If there are no parameters there is nothing to do here. You could do a more thorough check here to ensure the parameters are the correct ones, but this will suffice for most purposes. Remember this page will be called by the Javascript in the MapSearchControl.js that is provided by Microsoft.
private void Page_Load(object sender, System.EventArgs e)
{
if(Request.QueryString.Count > 0)
{
Response.Clear();
Response.Write(Search());
}
}
The next thing you need to do is write the Search() method.
private string Search()
{
string results = string.Empty;
string searchParams = BuildParams();
HttpWebRequest searchRequest =
CreateRequest();
System.Text.UTF8Encoding encoding =
new System.Text.UTF8Encoding();
byte[] bytes =
encoding.GetBytes(searchParams);
searchRequest.ContentLength =
bytes.Length;
Stream requestStream =
searchRequest.GetRequestStream();
requestStream.Write(bytes,
0, bytes.Length);
requestStream.Close();
try
{
results =
GetResults(searchRequest);
}
catch(Exception ex)
{
Console.Out.WriteLine(ex.Message);
}
return results;
}
In this Search method you will need to build up the list of parameter to call through to the MSN search page. This list will be identical to the parameters passed to this page, so it will look like this:
private string BuildParams()
{
string a=Request["a"];
string b=Request["b"];
string c=Request["c"];
string d=Request["d"];
string e=Request["e"];
string f=Request["f"];
string g=Request["g"];
string i=Request["i"];
string r=Request["r"];
string searchParams =
"a="+a+"&b="+b+"&c="+c+
"&d="+d+"&e="+e+
"&f="+f+"&g="+g+"&i="+i+"&r="+r;
return searchParams;
}
You then need to create an HTTPWebRequest to call the MSN search page. This has been encapsulated in the BuildRequest Method.
private HttpWebRequest CreateRequest()
{
HttpWebRequest searchRequest =
(HttpWebRequest)
WebRequest.Create(
"http://local.live.com/Search.ashx");
searchRequest.Method = "POST";
searchRequest.ServicePoint.Expect100Continue =
false;
searchRequest.ContentType =
"application/x-www-form-urlencoded";
return searchRequest;
}
Finally you need to extract the results from the stream that is returned from the MSN search page and redirect them to the output of this page.
private string GetResults(
HttpWebRequest searchRequest)
{
string results = string.Empty;
HttpWebResponse searchResponse;
searchResponse =
(HttpWebResponse)searchRequest.GetResponse();
Stream receiveStream =
searchResponse.GetResponseStream();
System.Text.Encoding encode =
System.Text.Encoding.GetEncoding("utf-8");
StreamReader readStream =
new StreamReader(receiveStream, encode);
Char[] read = new Char[256];
//Reads 256 characters at a time.
int count = readStream.Read( read, 0, 256 );
while (count > 0)
{
String str = new String(read, 0, count);
results += str;
count = readStream.Read(read, 0, 256);
}
searchResponse.Close();
return results;
}
The full code file can be downloaded from http://www.viavirtualearth.com/MyVirtualearth/MapSearchControl/Where code.pdf.
Building the Ads, or What, search page is very similar. The methods that you will need to change are BuildParams and CreateRequest.
The BuildParams method changes because the MSN ads page only takes four parameters.
private string BuildParams()
{
string a=Request["a"];
string b=Request["b"];
string c=Request["c"];
string d=Request["d"];
string searchParams =
"a="+a+"&b="+b+"&c="+c+"&d="+d;
return searchParams;
}
The CreateRequest method changes because instead of calling the Search.ashx page your Ads proxy page will need to call the MSN Ads.ashx page.
private HttpWebRequest CreateRequest()
{
HttpWebRequest searchRequest =
(HttpWebRequest)
WebRequest.Create(
"http://local.live.com/ads.ashx");
searchRequest.Method = "POST";
searchRequest.ServicePoint.Expect100Continue
= false;
searchRequest.ContentType =
"application/x-www-form-urlencoded";
return searchRequest;
}
The code for this page can be downloaded from http://www.viavirtualearth.com/MyVirtualearth/MapSearchControl/What code.pdf.
Adding More Features to the Maps
Once you have got the MapSearchControl running in your application you can use all the other documented techniques found on http://www.viavirtualearth.com/ to manipulate the map.
The team at ViaVirtualEarth would love to hear about the applications you build and add them to the gallery.


