Interactive Mapping Blog

Mapping Solutions News

Archive for the ‘Microsoft Virtual Earth’ Category

‘Mapmania’ : Why Maps are the New Interface and will be a Defining Trend of 2009

Tuesday, February 3rd, 2009

The team at Trendwatching.com have been gazing into their crystal balls to predict the defining consumer trends of 2009 which could be applied profitably and help you ride out the recession.

‘Mapmania’ (everything mapping related) was listed in the top 10 trends for 2009. Currently mapping works well for obviously geographically dependent companies such as estate agents or travel companies who have utilised technologies such as Google maps and Microsoft Virtual Earth, and its popularity will continue to grow in 2009 for these types of businesses. However, Trendwatching.com predicts that the use of mapping will gradually infiltrate every part of our daily lives. As they quite rightly pointed out, a map interface is a universally familiar method of organizing, finding and tracking relevant information on objects, events and people. Therefore, it makes sense that consumers will want to utilise mapping for everyday tasks such as meeting friends or finding out what’s happening in their local communities. 

As the data providers and technology companies add to their offering every day, this will allow consumers to use mapping and GPS services like never before and over the coming year they will come to expect mapping interfaces to be a standard offering.

Other trends identified by the Trendwatching team include the next phase of consumer interaction, Feedback 3.0. Those companies who enter into a dialogue with their clients, providing feedback to the negative comments as well as positive, will get top marks from the consumer’s perspective, and as a consequence they will gain more business.

Trendwatching also state that any brand would be ’stupid’ not to at least dabble in these services, to measure how they can have an impact on your business.

Using Virtual Earth Webservices with PHP

Wednesday, January 14th, 2009

This last week we have been working on a Virtual Earth project with a client who have a large php extranet . As part of the mapping integration we have been helping their developers use the Virtual Earth webservices for Geocoding addresses but there seem to be no up to date code samples for doing this in PHP.

The Soap Options

There are a few options for calling SOAP webservices in PHP, the two most popular seem to be NuSoap and the PHP5 built in SoapClient. Most of the previous PHP examples for calling the older MapPoint web services are using NuSoap I believe because of early issues with the built in SoapClient, so that is where we started.

NuSoap

We managed to get the GetClientToken method working using NuSoap pretty quickly but came across issues when we started trying to call the geocodeservice. Initially we found an issue with the encoding of the SOAP request being rejected by the geocodeservice but after some digging found an option to change it in NuSoap by uncommenting the line "var $soap_defencoding = ‘UTF-8′;" in nusoap.php.

Once we had that working, we were getting errors suggesting we were not sending a Credentials parameter to the GeoCode method, even though we were. We tried lots of different approaches including creating the SOAP envelope by hand and sending it using NuSoap but nothing seemed to work. So we started again and this time tried the PHP5 built in SoapClient.

PHP5 SoapClient

After converting the code to the PHP5 SoapClient we started to have some joy with the GeoCode method and eventually managed to get it to return a result. With a bit of debugging to see the structure of the result we eventually had access to the GeoCodeResult object and its properties!

So rather than using two different SOAP clients we now changed our GetClientToken code to use the PHP5 SoapClient, but again it didn’t exactly go to plan. The PHP5 SoapClient does not seem able to download a password protected WSDL, even when using it’s documentation credentials options. We tried putting the username/password in the wsdl url but that didn’t work either so eventually we had to download a local copy of the wsdl and use that.

The Final Code

The code is split into two parts, the token request:

  //used to get Virtual Earth webservice token, returns token as string
  function GetToken($vepUID,$vepPWD){

    //have to use local copy as cannot get php to send credentials to get it from live. See http://bugs.php.net/bug.php?id=27777 for php bug report
    //remember to update local wsdl when using production
    $vetsWsdl = 'tokenservice.wsdl';
    //attempted at sending credentials in url, does work
    //$vetsWsdl = 'http://' . $vepUID . ':' . $vepPWD . '@staging.common.virtualearth.net/find-30/common.asmx?wsdl';
    //live url $vetsWsdl = 'http://' . $vepUID . ':' . $vepPWD . '@common.virtualearth.net/find-30/common.asmx?wsdl';

    //create soap client, setting username and password used when calling method
    $client = new SoapClient($vetsWsdl, array('login'=>$vepUID,'password'=>$vepPWD,'trace' => 1));//trace allows us to see last response and request for debugging

    $client_ip = $_SERVER['REMOTE_ADDR'];//wont work for localhost!
    //$client_ip = '86.17.152.241';

    //Build the tokenspecification object http://msdn.microsoft.com/en-us/library/cc966768.aspx
    $tokenSpecification = array(
        'ClientIPAddress' => $client_ip,
        'TokenValidityDurationMinutes' => 15);
    $getClientToken = array('specification' => $tokenSpecification);

    //call GetClientToken method of token service http://msdn.microsoft.com/en-us/library/cc980876.aspx
    $result=$client->GetClientToken($getClientToken);

    //Make sure no fault or error has occurred.
    if ($client->fault)
    {
      die('Fault occurred using Web Service: '.print_r($res,true));
    }
    $veToken = $result->GetClientTokenResult;
    return $veToken;
  }

and the GeoCode request:

  //Virtual Earth Platform ID goes here.
  $vepUID = 'YOURUSERID';
  //Virtual Earth Platform password goes here.
  $vepPWD = 'YOURPASSWORD';

  $veToken = GetToken($vepUID,$vepPWD);//call token function

  //Get geocode
  $vegWsdl = 'http://staging.dev.virtualearth.net/webservices/v1/metadata/geocodeservice/geocodeservice.wsdl';
  //live url $vegWsdl = 'http://dev.virtualearth.net/webservices/v1/metadata/geocodeservice/geocodeservice.wsdl';

  //Create soap client
  $client = new SoapClient($vegWsdl, array('trace' => 1));//trace allows us to see last response and request for debugging

  //create credentials object and fill properties http://msdn.microsoft.com/en-us/library/cc966923.aspx
  $credentials = array('Token' => $veToken);
  //set geocoding query
  $query = 'SG15 6YF, uk';
  //create geocoderequest object and fill properties http://msdn.microsoft.com/en-us/library/cc980924.aspx
  $geocodeRequest = array('Credentials' => $credentials,'Query' => $query);

  //build geocode methods 'request' parameter
  $geocode = array('request' => $geocodeRequest);

  //call web service method called GeoCode http://msdn.microsoft.com/en-us/library/cc966817.aspx
  $result=$client->Geocode($geocode);

  //Make sure no fault or error has occurred.
  if ($client->fault)
  {
    die('Fault occurred using Web Service: '.print_r($res,true));
  }

  //Get GeocodeResponse  object from $result http://msdn.microsoft.com/en-us/library/cc980928.aspx
  //get first GeocodeResult object as there will be more than one, starting with the most relevant. http://msdn.microsoft.com/en-us/library/cc980950.aspx
  //get the GeocodeLocation object http://msdn.microsoft.com/en-us/library/cc966778.aspx
  //get the Latitude value
  echo $result->GeocodeResult->Results->GeocodeResult[0]->Locations->GeocodeLocation->Latitude . '<br />';
  //get the Longitude value
  echo $result->GeocodeResult->Results->GeocodeResult[0]->Locations->GeocodeLocation->Longitude . '<br />';

 

Final Thoughts

It’s been a long time since we have done any real PHP coding and the one thing this exercise has reminded us is just how far .Net has come over the years compared to PHP. What would take minutes to do in .Net has taken hours to figure out and debug in PHP, and with no strongly typed objects it was even more difficult to get at the result objects. But we do not claim to be PHP experts, maybe there are easily and less taxing ways to achieve this, we would love to hear if you know more!

Multimap Launch Free Mapping for Small Businesses

Tuesday, November 18th, 2008

At Earthware, we have believed for some time that Microsoft/Multimap has been disadvantaged vs. Google API which offers embedded maps with free transactions to small mapping clients. With this in mind, we thought we would draw your attention to Multimap’s recently launched embedded mapping product which sees them fighting back Google in offering mapping for free to low volume commercial users.

This new version of the Multimap API allows website owners to embed a customised map into their site taking advantage of Microsoft Virtual Earth’s aerial imagery: all it takes is a single line of HTML code.

The key features are as follows:

· Designed for use by small businesses, personal websites and hobbyists.

· Includes up to 50,000 transactions per year (which Multimap track).

· It takes just as single line of HTML code to embed the map.

· Choice of map styles (TeleAtlas, Ordance Survey, and Barts) and map views (road view or aerial view, including coverage of the US using Microsoft Virtual Earth).

· The HTML code includes four hyperlinks back to Multimap allowing the user to see the location on Multimap with a bigger map, POI’s and business listings; view the location in Bird’s Eye; get directions to the location; get directions from the location.

To embed a map in your site simply:

1. Go to Multimap.

2. Search for your location on Find a Map.

3. Click on “link” on the top right of the map.

4. A box opens; click to accept T’s and C’s.

5. Select to “customise the map” (select the size of the map and move the red circle).

6. Copy and paste the line of HTML code.

Here’s an example of what the map will look like in your site as well as the links back to Multimap for POI’s, Bird’s eye etc:

We believe that Multimap have seen a rapid uptake in these maps into client’s websites. For a list of a few examples please click here.

Before you think this is the panacea of mapping we ought to mention that there are some downsides to the ‘embedded maps’ compared to a licensing for full commercial usage. These being:

  • Branding – when using the free mapping, the user leaves the client site to view the data and information within a clearly Multimap branded site. This may mean the user will associate the experience as much with the Multimap brand as they do with your brand.
  • Advertising – In the Terms and Conditions, Multimap reserve the right to add advertising to the embedded maps which is controlled solely by them and cannot be removed in the free version. There is always the possibility that the advertising will not fit well with your own site branding or content.
  • Usage – the maps cannot be embedded in internal business applications such as BI or CRM systems.

After all, it wouldn’t be reasonable to release an all singing and dancing version with unlimited transations for free – Microsoft and Multimap are businesses after all.

If you want our view, we think this is great news for clients who now have more choices in mapping technologies for low volume usage, or where they want to test out user experiences before dipping into their pockets for significant licence fees for wider usage. A thumbs up from us for Multimap!

Earthware and Microsoft/Multimap at Agency Expo

Sunday, October 19th, 2008

Although it seemed that both exhibitor numbers and attendees were down at Agency Expo this year, there was a lot of enthusiasm for those that stopped by at the Microsoft / Multimap stand.

Multimap have recently released a new “embedded” mapping option for users with less than 50,000 transactions per year.  If you want any further information I would recommend contacting Multimap directly via their website www.multimap.com.  We also witnessed many attendees still being “wow”ed by Bird’s Eye imagery which is available through either Multimap or Microsoft Virtual Earth.

We had a really good time explaining how you can get the best of the Virtual Earth platform especially using Earthware’s residential and commercial property mapping products.  We have been delighted to partner with Microsoft and Multimap to give every Estate Agent in the UK (irrespective of size) the opportunity to integrate Virtual Earth into their website and create a highly visual experience for their customers.

Enough of the sales pitch though.  What we also really enjoyed showing was where mapping is really going.  We were delighted to show Earthware’s big first in getting StreetView for 1,000 km of London streets launched before Google.  Please see our other blog article for more details or just click on the following links to have a look for yourself at Piccadilly Circus, Buckingham Palace, Tower Bridge or even an attack from a giant spider.

We were also delighted to show off what was possible using the new photosynth product released from Microsoft labs.  This can be integrated with mapping to enhance the visual experience for users/customers.  I even had a play myself and so click here (or see the insert below) to see the stand in photosynth.  You might also want to have a look at how Microsoft’s Tim Warr has integrated photosynth into a mapping environment in his blog article.

Neil

London UK street level views now live, but not from Google!

Thursday, October 16th, 2008

It’s an exciting day here at Earthware, after months of development on the latest version of our Earthware Property real estate mapping solution it’s now live on the commercial property portal Novaloca.com  with brilliant street level views of central London from our partners Seety.

To try out street level views for yourself, try the links below to some famous London landmarks:

london-bridge-thumb Earthware Property already includes the best aerial and birdseye imagery available by using Microsoft Virtual Earth as its mapping provider, now with Seety’s street side views Earthware Property offers a world leading mapping solutions to estate agents and property web sites.

We are proud to be partnering with Seety on this project who are an amazing company taking consumer level electronics and proprietary software and producing street level views all over the world. Not only are Seety innovators in the street level view market but they have beaten the biggest player in the market, Google, to making one of Europe’s major cities publicly available.

The area currently available covers central London as shown below:

coveragemap

If you want to find our more about using Earthware Property for your own web site or about licensing and commissioning street level views of your city please contact us.

Street Level Views Are Coming to EarthwareProperty

Monday, October 13th, 2008

Earthware’s aim has always been to “use the latest mapping technology to create compelling visual experiences to bring our clients’ products and services to life”. Therefore you can imagine our excitement when we saw the latest development in mapping being released: panoramic street level imagery. What better way to make a map compelling and to bring something to life than being able to see a location on your PC as though you are actually standing there and taking a walk around?!

Seety were the first to bring street level panoramic views to the UK having driven over 1000km of the streets in central London and taken over 170,000 photographs. Now to realise our commitment to using the latest mapping technology, Earthware have joined forces with them. Street Level View as we are calling it will be implemented into our existing EarthwareProperty maps in the coming days to become the first implementation of this latest mapping technology in the UK. Our Operations Director, Neil Osmond says of this development;

“At Earthware, we are delighted to be involved in somewhat of a coup in partnering with Seety to bring Street Level View to the UK before anyone else.  We are sure that people will really enjoy experiencing travelling round the streets of London through their PC.”

Having had a long standing relationship with commercial property finder NovaLoca, (Earthware built the NovaLoca site which also became the first implementation of EarthwareProperty) it seemed natural that NovaLoca also be the launch place for the first implementation of Street Level View imagery in the UK. Key to NovaLoca’s success has been their use of technology to differentiate them against similar offerings in its goal to make marketing commercial property easier for agents and finding commercial property easier for occupiers. Therefore it is not surprising that they were keen to be on board too. With Street Level View site users looking for commercial property in London will be able to ‘stand’ in front of a chosen property (see the facia not just the roof!), look at the one next door and even take a ‘walk’ to the nearest tube station or shop.

A note for the security and privacy conscious among you; Seety have carefully processed every image and blurred out all car registration plates and people’s faces to ensure their identity is not shown.

Keep an eye on the Earthware blog; we will be announcing the release of Street Level View in EarthwareProperty here first and if you would like any more information please contact us on 0845 6429880 or email us at info@earthware.co.uk.

Earthware invited to join the Microsoft / Multimap mapping team for Agency Expo

Friday, October 3rd, 2008

Earthware were delighted to be invited to join the Microsoft / Multimap team for the upcoming Agency Expo event.  Microsoft were very keen to involve a partner organisation to explain to potential clients what the full range of possibilities are for their mapping products to drive business opportunities and conversions

Neil Osmond and Lauren Eden from Earthware will both be available over the 14th and 15th October to answer questions and demonstrate the possibilities for mapping.  If you would like to meet with one of us, or any member of the Microsoft / Multimap team, please either contact us beforehand to set up an appointment or drop by the stand.

Attendance of the Agency Expo event is free and you can register at http://www.agencyexpo.co.uk/.

Virtual Earth makes a ‘Quantum Leap’ in 3d

Thursday, September 25th, 2008

This new release of virtual earth has some major updates to the 3d plugin. The two biggest changes being real time clouds and ’street view’ imagery for 3d models.

The first time I saw the real time clouds demo’d last week my first thought was “this looks just like the opening titles to Quantum Leap!”. Zooming through the clouds at as if in a plane is really cool even if it is a bit of a gimmick.

To give you an idea of what it looks like take a look at the video below of Mount Snowdon in Wales. Unfortunately I couldn’t get our normal capture program (fraps) working with the latest 3d plugin so it’s not very smooth, and certainly not ‘zooming’ but it still adds a lot of atmosphere to the landscape.

Go and give it a try for yourself here are a few mountains to try:

Now if only we could commercially sell these 3d videos flyovers, like we currently do with Google Earth video tours, it would be brilliant, but Microsoft’s 3rd party licensing deals are always the issue.

That’s all for now next time we will look at the new 3d street view imagery that’s been added to some of the modeled cities.

Virtual Earth, Microsoft releases ver 6.2 today!

Sunday, September 21st, 2008

Its been rumoured for a few days but now its official the new version of the Virtual Earth ajax web control has been released. Considering this is just a minor release it  has a lot of features packed into it:

  1. Localised map tiles for German, French, Italian and Spanish

    image

  2. Built in client side pushpin clustering
  3. Landmark based routing, currently supported in the USA for fast food restaurants and petrol stations
  4. Massive improvements in European and Worldwide addresses parsing specifically improved for UK, France, Italy and Spain
  5. Static maps for mobile (see more below)
  6. Ability to disable the default virtual earth tiles, when adding custom tile layer (no word on how to license this scenario though)

There is now also a set of Virtual Earth web services (seperate from the mappoint web services):

  1. Imagery meta data webservice – gives date range of imagery and provider details (only for ortho imagery)
  2. Geocoding web service – using the virtual earth geocoder, not the mpws one and with the improvements as mentioned above
  3. Reverse geocoding worldwide – available wherever routing is available
  4. Search and routing – web service methods to match the ajax controls existing methods
  5. Image tiles and static maps – you can now request tiles via the web service rather than directly to use in your own custom map controls and also for mobile devices

There have even been some updates to the 3D control and content:

  1. Realtime weather and clouds, the clouds look great as you fly through them

    London's real time rain clouds ;-)

  2. Improved installed for the 3d plugin
  3. More options available to user including disabling weather (when its raining and you are showing the client there lovely new beach resort :-) )
  4. Improved texture quality on 3d buildings
  5. Improved ’street level’ textures on buildings – this is Microsofts answer to Google Streetview where they have textured the lower parts of buildings with imagery taken at street level
  6. Import of models from your own hosting (no need to upload to live.com) in the lightwave obj format
  7. New version of 3dvia shape

Getting Stuck In

To get started with version 6.2 first try the interactive sdk then read through the reference sdk including the whats new section.

Summary

There seem to have been a bit of a delay getting this release live as it was due to be released on the 22nd but it goes to show how big a release it is. So as you can see the Virtual Earth dev team have been really busy. Its brilliant to see how many features requested by the developer community have been released. To be honest when I was asked what new features we wanted to see in the future there weren’t many I could think of any more, it just goes to show how mature a product the ajax control is becoming. Now access to the tiles have been officially supported it will be interesting to see what commercial uses people find for this and the mobile maps.

It’s also great to see the hard work of the MultiMap team making it into the Virtual Earth control as they contributed to the pushpin clustering and the massive improvements in worldwide geocoding and address parsing.

Creating simple drive time maps with Virtual Earth

Saturday, September 20th, 2008

download code download code

distance coverable from central london in 30 minutes A feature that we are sometimes asked for with our mapping products and solutions is “can you show a map of how far I can travel by car from X in Y minutes?”. I was recently inspired by a demo of the Masternaut fleet management system at the UK Virtual Earth partners day, that showed very nice detailed polygons of how far you could travel my car from a given point in a given time.

Now I’m sure Masternauts solution, which works almost instantly, has a massive backend data store to query all this information but it got me wondering if we could do a very simple version of this just using the data available from Virtual Earth?

How might we achieve this?

image The basic process behind this idea is to create a set of “spokes” at evenly distributed angles around a centre point (the start location) like a bicycle wheel.

The diameter of the “wheel” being set to the maximum possible distance that could be travelled in a straight line from the centre of the “wheel”.

We then need to get the latitude and longitude of the point at the end of each “spoke” and use this to get directions, using Virtual Earth, from the centre of the “wheel” to each “spoke” end point.

We should then be able to go through the details of each “spoke” route returned and work out how far along the route we could get in the given time. This should give us a set of latitude / longitude points around the centre of our “wheel” indicating how far along each “spoke” we can travel in the given time, join them together in a polygon and you have your map!

So the basic process is:

1) Get X spoke point positions (lat / lon) at equal distance and equally distributed around a start point

2) Calculate the full driving directions from the start point to each of the X spoke positions

3) Go through each route returned and work out how far along the route we could travel in the given time, get the position (lat / lon) of this point

4) Add all the points from 3 and draw a polygon on the map showing the boundaries of the possible locations.

The Code

I would usually write this as a javascript class using the asp.net ajax libraries but to make it as readable as possible and portable to any framework it is coded as simple function calls with a few global variables.

First we have to work out the position of each end point of the “spokes”:

//starts the process of calculating the driving distances
function GetDrivingDistance(startpoint, mins, numspokes, maxspeedkmph) {
    gmins = mins; //need to use later
    gnumspokes = numspokes;
    gstartpoint = startpoint;
    
    //add original start point as pushpin to map
    var pin = new VEShape(VEShapeType.Pushpin, startpoint);
    gmap.AddShape(pin);
    
    //calculate maximum distance possible in a straight line
    //at the maxspeed
    var maxdist = (maxspeedkmph/60) * mins;
    
    gspokearray = new Array(); //new array to contain spoke VELatLong objects
    groutesarray = new Array(); //new array to contain the VERoute objects calculated
    
    //setup verouteoptions for directions
    gropts = BuildRouteOptions();
    
    //calculate position, in lat lon, of each spoke
    //assuming maximum distance away
    for (i = 0; i < numspokes; i++) {
        var bearing = (360 / numspokes) * i; //get bearing of current spoke
        gspokearray[i] = GetPointAtDistanceAndBearing(startpoint, maxdist, bearing);
 
        //get first route between startpoint and spoke endpoint
        //cannot call more than one GetDirections at once
        if (i == 0) {
            document.getElementById("progress").innerHTML = "Proccessing step 1 of " + gnumspokes;
 
            //plot spoke
            if (gdebug) gmap.AddShape(new VEShape(VEShapeType.Pushpin, gspokearray[i]));
            
            //get directions
            gmap.GetDirections(new Array(startpoint, gspokearray[i]), gropts);
        }
    }
}

This  function starts by setting some global variables and then adds a pushpin to the map at the location of the supplied VELatLong startpoint parameter.

The we calculate the maximum possible distance coverable in a straight line at the parameter maxspeedkmph (max speed in km per hour).

Then we setup a few arrays for storing results in later, and create the VERouteOptions class to be used in all routing (see full code for function BuildRouteOptions). The route options set a callback method called OnRoutingComplete when the route is complete

Now we loop through the number of spokes requested (parameter numspokes) and work out the bearing of each spoke around the start point using the GetPointAtDistanceAndBearing method (see full code).

After updating the UI with our progress we optionally plot the spoke end point if the code is in debug mode (see full code) just so we can see what is going on.

Finally we fire off the first request to VEMaps GetDirections method for the first spoke point.

When the GetDirections is complete the OnRoutingComplete function is called:

//the callback function when a route completes
function OnRoutingComplete(result) {
    //add new route to groutesarray
    groutesarray.push(result);
    if (groutesarray.length == gnumspokes) {
        //now all routing is complete start next stage
        ProcessDrivingRoutes();
    }
    else {
        //update progress
        document.getElementById("progress").innerHTML = "Proccessing step " + (groutesarray.length + 1) + " of " + gnumspokes;
 
        //debug plot spoke and route end
        if (gdebug) {
            gmap.AddShape(new VEShape(VEShapeType.Pushpin, gspokearray[groutesarray.length]));
            if(result.Distance>0) gmap.AddShape(new VEShape(VEShapeType.Pushpin, result.RouteLegs[0].Itinerary.Items[result.RouteLegs[0].Itinerary.Items.length-1].LatLong));//end of route, to see how close it got to spoke
        }
          
    
        //get next route
        gmap.GetDirections(new Array(gstartpoint, gspokearray[groutesarray.length]), gropts);
    } 
}

This adds the returned VERoute object to an array for processing later and then either calls ProcessDrivingRoutes if all routes have been completed or calls itself again with the next “spoke” position.

Once all routes have been completed the ProcessDrivingRoutes function is called:

function ProcessDrivingRoutes() {
    var pointsarray = new Array();
    var numroutesnotfound = 0;
    //process each route result
    for (i = 0; i < gnumspokes; i++) {
        //check route found, or if was in middle of sea etc so nothing returned!
        if (groutesarray[i].Distance > 0) {
            //work out how far down route we can actually get in the time supplied
            var totaltime = 0;
            for (var ii in groutesarray[i].RouteLegs[0].Itinerary.Items) {//will only be one RouteLeg
                //is current leg time greater than time supplied?
                var items = groutesarray[i].RouteLegs[0].Itinerary.Items;
                totaltime += items[ii].Time; //calculate the cumlative time of the route so far
                if (totaltime >= gmins * 60) {
                    //work out average speed between this point and the last
                    var routetimesecs = items[ii - 1].Time;
                    var avspeedkmph = 0
                    //check route time is greater than zero, as some itineraries can have zero time and distance
                    if (routetimesecs > 0) {
                        avspeedkmph = items[ii - 1].Distance / (routetimesecs / 360);
                    }
 
 
                    //work out aprox how far along route between this point and the previous
                    //you can get in the remaining time at the average speed
                    var timeleftsecs = (gmins * 60) - (totaltime - items[ii].Time); //time left from previous point
                    var maxdist = (avspeedkmph / 360) * timeleftsecs;
 
                    //work out bearing between previous point and this one
                    var bearing = GetBearingBetweenPoints(items[ii - 1].LatLong, items[ii].LatLong);
 
                    //work out new point along route between previous point and this one
                    //that can be reached in the remaining time
                    var newpoint = GetPointAtDistanceAndBearing(items[ii - 1].LatLong, maxdist, bearing);
                    pointsarray.push(newpoint);
                    break; //exit loop as have maximum point reachable in time given     
                }
            }
        }
        else {
            numroutesnotfound++;
        }
    }
    
    //debug
    if (gdebug) {
        alert("routes not found: " + numroutesnotfound);
        alert("routes found: " + pointsarray.length);
    }
 
    //we have all our maximum points in each direction
    //now draw the polygon representing the points
    var poly = new VEShape(VEShapeType.Polygon, pointsarray);
    poly.HideIcon();
    gmap.AddShape(poly); //add to map
    gmap.SetMapView(pointsarray);
 
    //reset button
    document.getElementById("btnCalc").disabled = false;
    document.getElementById("btnCalc").value = "Calculate";
 
    document.getElementById("progress").innerHTML = "Proccessing complete";  
}

This loops through the routes returned in the groutesarray and first checks if the route has any distance, if it doesn’t we ignore it as is means a route could not be found between the startpoint and a specific “spoke” end point.

Now we loop through each stage of the route (there will only be one route leg) working out how far we can get along the route before the maximum time in minutes (as supplied to GetDrivingDistance as parameter mins)  is exceeded.

Once we find the 2 stages of the route that are either side of the maximum time we calculate the distance between the 2 stages of the route and the average speed along that part of the route (distance travelled / time taken). We can then work out the distance from the first of the 2 route stages to the final position possible to reach in the time given, and the direction of travel in degrees between the 2 stage’s start points. Finally we can work out the position (lat / lon) of this final reachable point by calling the GetPointAtDistanceAndBearing function again (see full code).

Now we have the point which we can reach along the route to the end point of the “spoke” in the given time limit. Finally we add this to an array and draw all the points in the array as a polygon on the map, zooming the map out using SetMapView so we can see the whole polygon.

So does it work?

As you can see in the demo, it does indeed plot a drive time polygon, which improves its accuracy as you increase the number of spokes. You can manually check a location within the polygon to confirm that you can actually reach it within the given time, and most of the time that works.

However there are a few issues…

What doesn’t work?

Well unfortunately there is a lot that doesn’t work:

1) Try centering the map near a costal region, you will see quite often the polygon drawn does not even include the start point. This is either because Virtual Earth used shipping lines to get a route (which head inland first to get to the port), or could not even find a route out to the middle of the sea.

image

2) Even in inland locations if there is not a road even remotely close to the end point of a spoke Virtual Earth will get a route to the nearest road which may be miles away in any direction. To see this for yourself change the gdebug global variable to true and see each spoke end point and each route end point ploted on the map, many of which are far apart.

3) Often the polygons points end up not plotting in order of increasing degrees around the start point mostly due to point 2 above. This can lead to points in the polygon crossing over as below:

image

4) Its SLOOOOOOWWW. As we seem to only be able to call one GetDirections at a time it takes forever to plot a map with a high number of spokes.

5) Exactly how accurate or even useful the results are is certainly questionable

6) It will of course not work if directions are not available in the region the map is covering.

7) Routes to the endpoint of the spoke might go a long way off the angle of the “spoke” to get to the final destination so getting a point along this route is never going to give a really accurate answer to the problem.

How could it be made better?

There are lots of simple ways this could be made to work better including:

1) Using country boundaries to work out when we are asking for a route in the sea and instead ask for a route to the very edge of the coast.

2) Fix the polygon points so they are in order when plotting on the map which should remove the crossing over effect discussed above.

3) Right now we are using the routleg itineraries to plot the data but these are not the exact route points but only the turn by turn points so are not as accurate. With a commercial account we could get to the full route data which might be able to be used to get a more accurate position of the polygons points.

Got an idea to make this better?

Do you have an idea for making this work better? Please add it to the comments below.

download code download code