Jean581393


Hi guys,

Briefly, this code used to work a couple weeks ago, but no longer. I suspect something possibly changed in the API or something related to that, but I can't find any documentation on it.

Anyway... if you mouse over one of the push pins and enter a postcode in the textbox, you should be able to get directions from the postcode you entered to that pushpin. A couple weeks ago, postcodes such as “3008” and “2072” (which are all valid Australian postcodes) used to work. Now, they’re treated as ambiguous. Worst thing is though, when you try 3008, the possible locations list doesn’t even list the Australian location.

Can someone help me please

Here’s the code in full….

----------------

Code Snippet

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head>

<title>Testing maps 7</title>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<script src="http://dev.virtualearth.net/mapcontrol/v4/mapcontrol.js"></script>

<script type="text/javascript">

var map = null;

var origin = ''; //Stores origin/postcode from user for subsequent reuse (useability requirement)

var locs = new Array;

var safeMode = false; // Flag determines if map should load in "safemode"

function GetMap()

{

map = new VEMap('myMap');

try

{

map.LoadMap();

map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);

}

catch (err)

{

safeMode=true;

}

RefreshPushpins();

map.SetMapView(locs);

}

function BuildPushpin(index, title, href, address)

{

if(safeMode)

{

// Display pushpins (so not a TRUE safemode, but its userfriendly) but turn off "directions" functionality -- as of 29/03/2007 VE doesn't support FF 2.0

return new VEPushpin(index, locs[index], 'pushpinleaf.gif', '<a href="'+href+'">'+title+'</a>', address, 'VEmap_iconStyle','VEmap_titleStyle','VEmap_detailsStyle');

}

else

{

return new VEPushpin(index, locs[index], 'pushpinleaf.gif', '<a href="'+href+'">'+title+'</a>', address+'<div class="originDiv"><span class="originTitle">Get me there:</span>From:&nbsp;<input type="text" class="originTextBox" id="origin'+index+'" value="'+origin+'" title="e.g. \'2000\' (postcode for Sydney, NSW, Australia)"/><input type="submit" class="originButton" id="submitOrigin'+index+'" value="Get Directions" onclick="GetJourney(\'origin'+index+'\','+index+');" /></div>', 'VEmap_iconStyle','VEmap_titleStyle','VEmap_detailsStyle');

}

}

function RefreshPushpins()

{

map.DeleteAllPushpins();

locs = new Array;

var loc = new VELatLong(-38.36460840347736, 144.94005203247073); locs.push(loc); var pin = BuildPushpin(0, 'Mornington Peninsula', '/article.aspx id=147335', ''); map.AddPushpin(pin);

var loc = new VELatLong(-38.40285712900175, 144.84302043914795); locs.push(loc); var pin = BuildPushpin(1, 'Peninsula Hot Springs', '/article.aspx id=147336', 'Springs Lane, Rye, Vic'); map.AddPushpin(pin);

var loc = new VELatLong(-38.21301302274773, 145.03319978713986); locs.push(loc); var pin = BuildPushpin(2, 'Relax, Go Fishing!', '/article.aspx id=147338', 'Mornington Pier, Schnapper Point Drive, Mornington, Vic'); map.AddPushpin(pin);

var loc = new VELatLong(-38.49185752765312, 144.88790988922122); locs.push(loc); var pin = BuildPushpin(3, 'Cape Schanck Lighthouse', '/article.aspx id=147339', '420 Cape Schanck Rd, Cape Schanck, Vic'); map.AddPushpin(pin);

var loc = new VELatLong(-37.14116138236253, 142.51893997192386); locs.push(loc); var pin = BuildPushpin(4, 'Grampians Personalised Tours & Adventures', 'http://www.grampianstours.com" target="new', 'Main St, Halls Gap, Vic'); map.AddPushpin(pin);

var loc = new VELatLong(-37.64984951217565, 142.34556198120114); locs.push(loc); var pin = BuildPushpin(5, 'Aquila Eco Lodges', '/article.aspx id=147340', 'Near Dunkeld, Vic'); map.AddPushpin(pin);

}

function GetJourney(originID, indexDestination)

{

//save it to 'origin' only if it's different and then refresh

if (document.getElementById(originID).value != '')

{

if (origin != document.getElementById(originID).value)

{

origin = document.getElementById(originID).value;

RefreshPushpins();

}

map.GetRoute(origin, locs[indexDestination], VEDistanceUnit.Kilometers, null, onGotRoute);

}

}

function onGotRoute(route)

{

var routeinfo="<h2>Directions:</h2>";

routeinfo+="<span id=\"totalDistance\">Total distance: ";

routeinfo+= route.Itinerary.Distance+" ";

routeinfo+= route.Itinerary.DistanceUnit+"</span>";

var steps="";

var len = route.Itinerary.Segments.length;

for(var i = 0; i < len ;i++)

{

steps+="<li>"+route.Itinerary.Segments[i].Instruction+" -- (";

steps+=route.Itinerary.Segments[i].Distance+") ";

steps+=route.Itinerary.DistanceUnit+"</li>";

}

routeinfo+="<ol>"+steps;+"</ol>";

document.getElementById("directions").innerHTML = routeinfo;

}

window.onload=GetMap;

</script>

<style type="text/css">

#VEContainer {

position: relative;

font-size: 11px;

font-family: verdana, arial;

width: 600px;

}

#myMap {

margin-top: 20px;

margin-left: 10px;

width: 600px;

height: 600px;

border:#555555 2px solid;

position:relative;

}

.VEmap_titleStyle

{

font-family:Arial;

font-size:12px;

}

.VEmap_detailsStyle

{

font-family:Arial;

font-size:12px;

}

#directions {

margin:10px;

}

#buttons {

margin-left: 10px;

margin-top: 15px;

float: right;

}

#buttons #close {

margin-left: 10px;

}

.originDiv

{

height:100%;

vertical-align:bottom;

width:100%;

margin-top:20px;

border-top:1px solid #999;

font-family:Arial;

font-size:12px;

}

.originTitle

{

font-family:Arial;

font-size:12px;

font-weight:bold;

margin-top:5px;

margin-bottom:15px;

display:block;

width:100%;

}

.originTextBox{

font-family:Arial;

font-size:12px;

width:90px;

}

.originButton{

width:90px;

font-family:Arial;

font-size:12px;

}

</style>

</head>

<body>

<div id="VEContainer">

<div id="myMap"></div>

<div id="directions"></div>

<div id="buttons"><a href="javascript:window.print();" id="print">Print</a><a href="javascript:self.close();" id="close">Close</a></div>

</div>

</body>

</html>





Re: Specifying a postcode only (Australia)

SoulSolutions


It never worked unfortunatly Sad

But by adding our country code afterwards it will Smile

Not very elegant I know but it does work.

try this:

function GetJourney(originID, indexDestination)

{

//save it to 'origin' only if it's different and then refresh

if (document.getElementById(originID).value != '')

{

if (origin != document.getElementById(originID).value + ', AUS')

{

origin = document.getElementById(originID).value + ', AUS';

RefreshPushpins();

}

map.GetRoute(origin, locs[indexDestination], VEDistanceUnit.Kilometers, null, onGotRoute);

}

BTW, where abouts are you I'm in Brisbane.

John.







Re: Specifying a postcode only (Australia)

Jean

That's really strange, b/c I'm 100% sure it worked a couple weeks ago. Oh well... ghost in the machine I guess.

Thanks for that bit of code - at least it works and it's much more userfriendly now. It also works if the user were to enter "Aus" or "Australia" themselves. Smile

I'm in Sydney.

Jean