mattoby_slim


Pushpin to Address, rather than Lat/Long
I'm having some massive difficulties in displaying a map with a pushpin set to a specific location. Basically, I have the address information in a database, and would like to show a map to the location with a pushpin.

The second step is get driving directions between two locations in the database, but let's tackle issue #1 first eh

<script src="http://dev.virtualearth.net/mapcontrol/v4/mapcontrol.js"></script>
<script>
var map = null;
var pinID = 1;

function GetMap()
{
map = new VEMap('myMap');
map.LoadMap();
}
map.FindLocation('812 10th Street, Milford, IA');
function AddPin()
{
var pin = new VEPushpin(
pinID,
map.GetCenter(),
null,
'My pushpin',
'This is pushpin number '+pinID
);
map.AddPushpin(pin);
pinID++;
}
</script>

<body onload="GetMap();AddPin();">

<div id='myMap' style="position:relative; width:400px; height:400px;"></div>

The map successfully adds a pushpin to the center of the map, but it is not getting the location I'm giving it.

Thanks in advance,
Matt




Re: Pushpin to Address, rather than Lat/Long

Derek Chan


Hmm I wonder how come people are having problems with doubling posting.... Anyways I've answered this one in the other duplicate post





Re: Pushpin to Address, rather than Lat/Long

Kartik Subramani

Hey matt,

you need to put the FindLocation call inside your AddPin function, before you create the new VEPushpin. That way your map will first center on the location, and then add the pushpin. Right now that FindLocation call won't ever be executed.

-Kartik






Re: Pushpin to Address, rather than Lat/Long

ben2004uk

Or, FindLocation can be given a callback function, which takes a single argument for the results (lat lng object) and you can add the pushpin within that function.

SDK has a lot about this so I would look there.