Our Friends

MP2K Mag

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:

CanberraAUUluruAUNewcastleAU

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)

Taking the search server side 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.

This article introduces a technique to bypass the security issue introduced by accessing a cross domain data source as introduced in the Finding section of Part 2 of Creating Your First Virtual Earth Web Page.

By moving the work of doing the search to your web server you can access the search functionality and return the result to your site.

In order to do this you will need to write some server side functionality. This article will demonstrate doing this with ASP.NET.

The final outcome can be viewed here.

The full code listing can be viewed here.

Using the System.Net.HttpWebRequest object in ASP.NET server code will allow you to post a request to the search page on the Virtual Earth site. To get started let�s create the HttpWebRequest object.

private HttpWebRequest CreateSearchRequest()
{
  HttpWebRequest searchRequest = (HttpWebRequest) WebRequest.Create("http://207.46.159.133/search.ashx");
  searchRequest.Method = "POST";
  searchRequest.ServicePoint.Expect100Continue = false;
  searchRequest.ContentType = "application/x-www-form-urlencoded";
  return searchRequest;
}

Then you will need to build the search parameters to pass to the Virtual Earth search page.

private string BuildSearchParams(string place)
{
  string a="";
  string b=place;
  string c="0.0";
  string d="0.0";
  string e="0.0";
  string f="0.0";
  string g="";
  string i="";
  int r=0;
  string searchParams = "a="+a+"&b="+b+"&c="+c+"&d="+d+"&e="+e+"&f="+f+"&g="+g+"&i="+i+"&r="+r;
  return searchParams;
}

In order to get the results from the search that was posted you will need to use the HttpWebResponse object. From this object you can read the results from a stream and decode them into a string.

private string GetSearchResults(HttpWebRequest searchRequest)
{
  string results = string.Empty;
  HttpWebResponse 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;
}

These methods can now be pulled together by a method that does the actual search.

private string Search(string place)
{
  string results = string.Empty;
  
  HttpWebRequest searchRequest = CreateSearchRequest();
  
  string searchParams = BuildSearchParams(place);
  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 = GetSearchResults(searchRequest);
  }
  catch(Exception ex)
  {
    Console.Out.WriteLine(ex.Message);
  }
  
  return results;
}

You now have a function that will call out to the virtual Earth search and return the results in a string object. You can use this in your own search page by calling the Search method from your Page.Load event handler

private void Page_Load(object sender, System.EventArgs e)
{
  if(Request["place"] != null)
  {
    Response.Clear();
    Response.Write(Search(Request["place"]));
  }
}

An example of this page is hosted at http://www.viavirtualearth.com/MyVirtualEarth/Search.aspx

You can test the search by adding a request parameter.

For example try http://www.viavirtualearth.com/MyVirtualEarth/Search.aspx?place=Portland, OR

You will see this returns Jscript that you can execute on your page. To use this you will need to eval this script. This is done in the third sample page.

var xmlhttp=false;

function DoFind()
{
  try
  {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  }
  catch (e)
  {
    try
    {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (E)
    {
      xmlhttp = false;
    }
  }
  
  if (!xmlhttp && typeof XMLHttpRequest!='undefined')
  {
    xmlhttp = new XMLHttpRequest();
  }
  
  xmlhttp.onreadystatechange=searchHandler;
  
  var where = document.getElementById("WhereText").value;
  
  xmlhttp.open("GET","search.aspx?place="+where,true);
  xmlhttp.send(null);
}

function searchHandler()
{
  if (xmlhttp.readyState==4)
  {
    eval(xmlhttp.responseText); 
  }
}

Rating

What did you think?

Not signed in. Sign in or sign up?

Others thought...

         

Average: 4 / 5