Bing Map Question

In the attached script is there a way to rewrite it so that instead of passing a lat /longitude value like
var shape = new VEShape(VEShapeType.Pushpin, new VELatLong( 34.2544631958008, -119.227882385254 ));

I could pass it an physical address?

Thanks for your help

Daniel
myempmap.txt
DanielManchesterAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rainer JeschorCommented:
Hi Daniel,
you should be able to use the following two functions:
function StartGeocoding( address )
{
	map.Find(null, address,  null, null, null, null, null, null null, null,GeocodeCallback);
}

function GeocodeCallback (shapeLayer, findResults, places, moreResults, errorMsg)
{
	// if there are no results, display any error message and return
	if(places == null)
	{
		alert( (errorMsg == null) ? "Address not found!!!" : errorMsg );
		return;
	}

	var bestPlace = places[0];

	// Add pushpin to the *best* place
	var location = bestPlace.LatLong;
	var newShape = new VEShape(VEShapeType.Pushpin, location);

	var desc = "<b>Latitude:</b> " + 
			  location.Latitude + "<br><b>Longitude:</b>" 
			  + location.Longitude;
	newShape.SetDescription(desc);
	newShape.SetTitle(bestPlace.Name);
	map.AddShape(newShape);
}

Open in new window


HTH
Rainer
DanielManchesterAuthor Commented:
Thanks Rainer,

That looks like it should work however my app requires that I be able to set the title and description of the new pushpin.  How could this be accomplished using the call back?

Thanks for help

Daniel
Rainer JeschorCommented:
Hi Daniel,
the following code works - please adjust the Bing key, the addresses and additional info and the map center lat/long.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html> 
	<head>
		<title>Map For: 'Vehicles'</title> 
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
		<script src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"></script> 
		<style> 
			.VEAPI_Pushpin{ text-decoration: none; }  
			.pinStyle1{ position:relative; background:url('pin1.gif') no-repeat 0 0; height:30px; width:25px; top:-15px; color:Red; text-align:center; font: bold 14px Arial; cursor: pointer;} 
			.pinStyle1 .text{ position: relative; top: 2px; }  
		</style>  
		<script type="text/javascript"> 
			var map = null; 
			var itemArray = new Array();
			var bmKey = "Your Key";
			
			function EventMapLoad() 
			{ 
				StartGeocoding("Any address 1","<div class='pinStyle1'><div class='text'> Custom Icon 1 </div></div>","Custom Title 1","Custom Description One");
				StartGeocoding("Any address 2","<div class='pinStyle1'><div class='text'> Custom Icon 2</div></div>","Custom Title 2","Custom Description Two");
  			}
			function CreateMap() 
			{  
				map = new VEMap('myMap'); 
				map.SetCredentials(bmKey);
				map.onLoadMap = EventMapLoad; 
				map.LoadMap(new VELatLong( 48.590005 , 12.024589), + '10', VEMapStyle.Road);
				map.LoadTraffic(true);
			}
			
			function StartGeocoding( address , customIcon, customTitle, customDescription)
			{
				map.Find(null, address,  null, null, null, null, null, null, null, null, makeCallback(customIcon, customTitle, customDescription));
			}
        
			function makeCallback(customIcon, customTitle, customDescription) {
				var geocodeCallBack = function(shapeLayer, findResults, places, moreResults, errorMsg) {
					if(places == null)
					{
						alert( (errorMsg == null) ? "Address not found!!!" : errorMsg );
						return;
					}

					var bestPlace = places[0];
           
					// Add pushpin to the *best* place
					var location = bestPlace.LatLong;
					var newShape = new VEShape(VEShapeType.Pushpin, location);
					newShape.SetCustomIcon(customIcon);
					newShape.SetDescription(customDescription);
					newShape.SetTitle(customTitle);
					map.AddShape(newShape);
				}
				return geocodeCallBack;
			}
		</script> 
	</head> 
	<body onload="CreateMap();">
		<div id='myMap' style="position:relative; width:1616px; height:876px;"></div> 
	</body>
</html>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DanielManchesterAuthor Commented:
Wonderful!  Just what I needed.

Thanks Rainer
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.