Bing Map AJAX API 7 - How to find out which address is invalid in request sent to directionsManager.calculateDirections method in case of error?


hi,

i using bing map 7 ajax api's directionsmanager.calculatedirections function route. few routes(e.g. "irving, tx" "freeport pkwy") bing returns error in response ("we didn't find results search"). here how can identify address invalid out of two?

e.g. see below example of www.bing.com/maps, show error message in front of invalid address textbox only:


this interesting 1 hadn't been asked before. looking in documentation found this: http://msdn.microsoft.com/en-us/library/hh312834.aspx 

however, noticed if render option "autodisplaydisambiguation" set true, default value, directions error event never fired , can't catch disambiguation error. having auto display disambiguous information nice looked how can figure out when no disambiguous result found waypoint. figured out "beforedisambiguationrender" event gets fired when in case , can use figure out waypoint has issue. funny enough event doesn't fire when "autodisplaydisambiguation" value set false, complete opposite issue before. so, in mind combined both of these solutions doesn't matter value of "autodisplaydisambiguation" is. added logic figure out index of waypoint in directions manager waypoint array , calculated number of suggested alternatives. if number of alternatives 0 fits case mentioned, if not 0 standard disambiguation apply. here code put together:

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html>    <head> 		<title></title> 		<meta http-equiv="content-type" content="text/html; charset=utf-8"/> 		<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script> 		<script type="text/javascript"> 		var map; 		var directionsmanager; 					   		function getmap() 		{ 			map = new microsoft.maps.map(document.getelementbyid('mymap'), {credentials: 'your_bing_maps_key'}); 			microsoft.maps.loadmodule('microsoft.maps.directions'); 		}        		function createdirectionsmanager() 		{ 			if (!directionsmanager)  			{ 				directionsmanager = new microsoft.maps.directions.directionsmanager(map);  				microsoft.maps.events.addhandler(directionsmanager, 'directionserror', function(e) {  					if (e.responsecode == microsoft.maps.directions.routeresponsecode.waypointdisambiguation) 					{ 						displaydisambiguation(e); 					} 				});  				microsoft.maps.events.addhandler(directionsmanager, 'beforedisambiguationrender', displaydisambiguation); 			} 		} 		   		function calculatedirections() 		{ 			if (!directionsmanager) {  				createdirectionsmanager();  			}  			directionsmanager.resetdirections();  			directionsmanager.setrequestoptions({ routemode: microsoft.maps.directions.routemode.driving });  			directionsmanager.setrenderoptions({ itinerarycontainer: document.getelementbyid('directionsitinerary') });  			directionsmanager.addwaypoint(new microsoft.maps.directions.waypoint({ address: 'seattle, wa' }));  			directionsmanager.addwaypoint(new microsoft.maps.directions.waypoint({ address: 'notavalidaddress' }));  			directionsmanager.calculatedirections(); 		} 		   		function displaydisambiguation(arg) 		{		 			var waypointidx = -1; 			var waypoints = directionsmanager.getallwaypoints(); 			 			for(var i=0;i< waypoints.length;i++){ 				if(waypoints[i].getaddress() == arg.waypoint.getaddress()){ 					waypointidx = i; 					break; 				} 			} 			 			var disambiguousresult = arg.waypoint.getdisambiguationresult(); 			var numresults = disambiguousresult.businesssuggestions.length + disambiguousresult.locationsuggestions.length; 			 			alert("unable find waypoint: '" + arg.waypoint.getaddress() + "' waypoint index: " + waypointidx + ". there " + numresults + " suggestions."); 		}       </script>    </head>  <body onload="getmap();">       <div id='mymap' style="; width:400px; height:400px;"></div>       <div>          <input type="button" value="calculate directions" onclick="calculatedirections();" />       </div>       <div id='directionsitinerary'> </div>     </body> </html> 

http://rbrundritt.wordpress.com



Bing Maps  >  Bing Maps Web Controls



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'