Greg 3.0


Hi there,

I'm encountering a small issue with the vemap control. As mentionned in the subject, I need to display a map centered on a specific location for which I dont have the coordinates. Thus, I need to use the find method first, and pass it the street address to retrieve the latlong to be used in the initialization routine. But as the find() method belongs to the vemap object which is not initialized when calling find(), it seems not to work... or the map first centers on the initial location then displays the right location, which is not good for my purpose...

So, do you have any idea on how to have a map coming up on page load centered on a specific street address

Thanks in advance, and best regards !

Greg




Re: Initialize a vemap with a latlong retrieved with find ?

RobertoRaimondo


I have a very stupid idea, but I'll try to share it with you...
You can instantiate two maps, one of them will be hidden, and will be the one you only use to call the Find method. Once you get the result you want, you can dispose of it, and initialize the second one which will be the one you actually show on your page. There may be some waiting time at the beginning for all the process to complete, but it may work.
As I said, it is quite stupid, but it may be enough for what you need. Let us know Wink

Roberto.







Re: Initialize a vemap with a latlong retrieved with find ?

RobertoRaimondo

This is what I intended, and it actually works. I don't consider it very well done, but maybe is enough for you...

Roberto.


Code Block

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Virtual Earth</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript" src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx v=6"></script>
<script type="text/javascript">
var fakeMap = null;
var realMap = null;

function startVE()
{
fakeMap = new VEMap('fakeMap');
fakeMap.LoadMap();
fakeMap.Find(null, "Piccadilly Circus, London, England", null, null, 0, 1, false, false, false, false, myCallback);
}

function myCallback(layer, resultsArray, places, hasMore, veErrorMessage)
{
fakeMap.Dispose();
fakeMap = null;
realMap = new VEMap('realMap');

var startLocation = null;

if (places && places[0] && places[0].LatLong)
startLocation = places[0].LatLong;

realMap.LoadMap(startLocation, 15);
}
</script>
</head>
<body onload="startVE()" style="margin: 0px">
<div style="position:absolute; top:0; left:0; height:600; width:600; overflow:hidden" id="realMap"></div>
<div style="position:absolute; visibility:hidden" id="fakeMap"></div>
</body>
</html>






Re: Initialize a vemap with a latlong retrieved with find ?

TheClansman

If you are always going to be centering the map on the same spot you could save the latlong returned from the find right in your page, then load the map to that position. This is fairly easy since the LoadMap function can take a LatLong and will center on it (if you have any questions just ask).

The other idea, if you don't know the latlong ahead of time would be too load the map in a hidden div, perform the find and then on the callback set the div to be visible.

Not sure if either of these would work, just some ideas.





Re: Initialize a vemap with a latlong retrieved with find ?

Derrick (MSFT)

Adding to TheClansman suggestion, Show a Loading message when the map is loading and doing a Find call, so users know that something is happening.





Re: Initialize a vemap with a latlong retrieved with find ?

Greg 3.0

Many thanks Roberto,

It works fine, but we have to support the dual initialisation...

RobertoRaimondo wrote:
I don't consider it very well done, but maybe is enough for you...

I'm feeling less lonely, and it's enough for me ya !

There used to be a comprehensive geocoding service here http://local.live.com/search.ashx but it's been made unavailable now... and unfortunately it was not replaced by something as simple and efficient...

Anyway, thanks again !

Greg