T V D


Hello Friends,

I am facing problems in finding information. Thsi is my script code. I have written 2 differnt functions, but both give same error on map.FindLocation() Error: 'Object doesn't support this proeprty or method'

Code Snippet

function DoFind() {

map.FindLocation(document.getElementById('whereText').value);

}

function FindLoc() {

alert(document.getElementById('whereText').value);

map.FindLocation(document.getElementById('whereText').value, onFoundResults);

}

function onFoundResults(e) {

var results = "More than one location was found. Please select the location you are looking for: <br>";

for (x=0; x<e.length; x++){

results += "<a href='javascript:map.FindLocation(\""+e[x].ID+"\");'>"+e[x].ID+"</a><br>";

}

document.getElementById('FIND').innerHTML=results;

}

HTML Code

<div id="FIND" style="position:relative;width:400px; top:408px; font-size:10pt">

<input type="button" value="Find" id="FindButton" name="FindButton" onclick="FindLoc()"/>

<input type="text" name="whereText" size="20" id="whereText" />

</div>

Can anyone tell, whts the problem. Any help is appreciated.

Thanks

Trupti Dalia




Re: Problems Finding Info

Derek Chan


You can't execute FindLocation anymore inside V5 because that function has been deprecated. You now need to do this through a Map.Find() and until more documentation can be released I'd recommend sticking to whats on the interactive SDK. To start things off anyhow, a simple Find call with callback would be:

Code Snippet
map.Find(what,where,null,null,index,null,null,null,null,null,callback);


Where "what" and "where" are your corresponding variables in the old V4 SDK

Hope that starts things off,







Re: Problems Finding Info

T V D

Dear,

Very Hard Luck. Still things are not working.

My JS file includes

Code Snippet

function Page_Load()

{

map = new VEMap('mymap');

map.LoadMap(new VELatLong(-33.7939, 151.1093), 10, 'r', false);

// insertMap = new VEMap('inMap');

// insertMap.LoadMap(new VELatLong(-33.7939, 151.1093), 2, 'h', true);

map.AttachEvent("onendcontinuouspan", GetLatLong);

map.AttachEvent("onendzoom", GetLatLong);

}

function FindWhatWhere() {

var what = document.getElementById('what').value;

var where = document.getElementById('where').value;

var index = 0;

if (what == "Search for a business or category")

what = "";

if (where == "Enter city, address, or landmark")

where = "";

alert("What = " + what + " Where = " + where);

// if (what != "" && where != "")

map.Find(what,where,null,null,index,20,true,true,false,true, ResultsFound);

//map.Find(what,where,null,null,index,20,true,true,true,true, ResultsFound);

alert("Find executed");

}

function ResultsFound(results) {

alert("Results Found = " + results.length);

}

On clickng the Fnd button, it displays, What & Where in alert, Find executed, but can't see any results. Map is still on the same location, same way. Actually, map shows the new location for just a sec & then returns to original / previous map. But, still callback, method is not exected as, the alert is not visible. Why so

One more point, I want to display the results in a Panel named ResultsPanel. How do I obtain putting the results in the panel.

What seems to be the problem.

Thanks

Trupti






Re: Problems Finding Info

T V D

Derek, Do u have any idea, why does the Find() not move the map to the found locations. It gets it, moves over their for a fraction of second & again returns on the previous map. Any clue regarding this problem.

Any help is highly appreciated.

Thanks





Re: Problems Finding Info

Derek Chan

Not too sure, I'd have to see your entire source to see whats going on. The first fraction of second you are describing is because the "setBestMapView" property is set to true by default of any V5 Find calls. Likely something in your code is sending the view back to the original spot.




Re: Problems Finding Info

T V D

This is my code - Default.aspx

Code Snippet

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>My Virtual Earth Application</< FONT>title>

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

<script src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx v=5" type="text/jscript"></< FONT>script>

<script src="js/Default.aspx.js" type="text/javascript"></< FONT>script>

</< FONT>head>

<body>

<form id="findForm" runat="server">

<asp:Table ID="HeaderTable" runat="server" Width="705px">

<asp:TableRow runat="server">

<asp:TableCell runat="server"><h1 id="headTitle" style="color:Fuchsia">My Virtual Earth </< FONT>h1></< FONT>asp:TableCell>

<asp:TableCell runat="server">

<div style="position:inherit; left:100px; width:300px; height: 30px;">

<fieldset>

<div id="whatContainer" class="inactiveTextBox">

<input id="what" name="what" type="text" title="Search for a business or category"

value="" style="width:200;" />

</< FONT>div>

<div id="whereContainer" class="inactiveTextBox">

<input id="where" name="where" type="text" title="Enter city, address, or landmark"

value="" style="width:200px;" />

<input id="searchbttn" type="submit" title="Search" value="Find" style="width:50px;" onclick="FindWhatWhere();"/>

</< FONT>div>

</< FONT>fieldset>

</< FONT>div>

</< FONT>asp:TableCell>

</< FONT>asp:TableRow>

</< FONT>asp:Table>

<asp:DropDownList ID="CollectionsDropDownList" runat="server">

<asp:ListItem>Add Pushpins</< FONT>asp:ListItem>

</< FONT>asp:DropDownList>

<asp:DropDownList ID="ShareDropDownList" runat="server">

<asp:ListItem>Send Email</< FONT>asp:ListItem>

</< FONT>asp:DropDownList>

<input id="routeBtn" name="routeBtn" type="button" value="Route Directions" onclick="createDrivePanel()" />

<div id="msve_TaskArea_positioner" class="expanded1">

<div id="msve_TaskArea_transparency">

<div id="msve_TaskArea_data">

</< FONT>div>

</< FONT>div>

<div id="msve_TaskArea_gutter" class="mid">

<asp:Panel ID="ButtonsPanel" runat="server" BorderStyle="Dashed" Direction="RightToLeft"

Height="50px" Width="883px" Wrap="False">

<input id="addPushPinBtn" style="background-position: center center; background-image: url(images/Pushpin.bmp);

width: 27px; background-color: transparent" title="Add Pushpin" type="button" onclick="crearePushpinPanel();" />

<input id="sendMailBtn" style="background-position: center center; background-image: url(images/mail.bmp);

width: 23px; background-color: transparent" title="Send EMail" type="button" />

<input id="zoomOutButton" style="background-image:url(images/ZoomOut.bmp); background-position: center center; width: 25px; background-color: transparent;" type="button" onclick="DoZoomOut();" title="Zoom Out"/>

<input id="zoomInBtn" runat="server" type="button" onclick="DoZoomIn();" style="background-position: center center; background-image: url(images/ZoomIn.bmp); width: 23px; background-color: transparent" title="Zoom In" />

<input id="panDwnBtn" runat="server" type="button" onclick="DoPanDown();" style="background-position: center center; background-image: url(images/PanDown.bmp); width: 26px; background-color: transparent" title="Pan Down" />

<input id="panRgtBtn" runat="server" type="button" onclick="DoPanRight();" style="background-position: center center; background-image: url(images/PanRight.bmp); width: 25px; background-color: transparent" title="Pan Right" />

<input id="panLeftBtn" runat="server" type="button" onclick="DoPanLeft();" style="background-position: center center; background-image: url(images/PanLeft.bmp); width: 28px; background-color: transparent" title="Pan Left" />

<input id="panUpBtn" runat="server" type="button" onclick="DoPanUp();" style="background-position: center center; background-image: url(images/PanlUp.bmp); width: 30px; height: 24px; background-color: transparent" title="Pan Up" />

<input id="birdsEyeBtn" runat="server" type="button" value="B E" onclick="ShowBEView();" disabled="disabled" />

<select id="mapStyle" name="mapStyle" onchange="ChangeStyle();">

<option value="r" selected="selected">Road</< FONT>option>

<option value="a">Aerial</< FONT>option>

<option value="h">Hybrid</< FONT>option>

</< FONT>select>

<input id="3dBtn" name="3dBtn" type="button" value="3D" />

<input id="2dBtn" name="2dBtn" type="button" value="2D" />

</< FONT>asp:Panel>

</< FONT>div>

</< FONT>div>

</< FONT>form>

<div id='mymap' style="position:absolute; left:300px; width:600px; height:550px; border:#555555 2px solid; top: 182px;" runat="server"> </< FONT>div>

<div id='inMap' style="position:relative; width:200px; height:200px; left:689px; top: -588px;"></< FONT>div>

<div id="directDIV" class="directDIV" style="width: 273px; position: absolute; height: 550px; background-color:silver; left: 13px; top: 188px;">

<label id="lbl"></< FONT>label>

</< FONT>div>

<asp:Panel ID="ResultsPanel" runat="server" BorderStyle="Solid" Height="84px" ScrollBars="Auto" Width="104px">

</< FONT>asp:Panel>

<br />

</< FONT>body>

</< FONT>html>

Default.aspx.js File

Code Snippet

// JScript File

// the Map object

var map = null;

var insertMap = null;

var latitude;

var longitude;

// Load the map

function Page_Load()

{

map = new VEMap('mymap');

map.LoadMap();

insertMap = new VEMap('inMap');

insertMap.LoadMap(new VELatLong(-33.7939, 151.1093), 2, 'h', true);

map.AttachEvent("onendcontinuouspan", GetLatLong);

// map.AttachEvent("onendzoom", GetLatLong); // This line was giving error on Zooming

map.AttachEvent("onchangeview", OnChangeView);

map.AttachEvent("onclick", GetLatLong);

map

}

// Calulates Latitude and Longitude

function GetLatLong(e)

{

//Get the pixel coordinates of where the map was clicked

var x = e.mapX;

var y = e.mapY;

var pixel = new VEPixel(x, y);

var latlong = map.PixelToLatLong(pixel);

//Round the coordinates to 5 decimal places

latitude = Math.round(10000*latlong.Latitude)/10000;

longitude = Math.round(10000*latlong.Longitude)/10000;

// insertMap.PanToLatLong(new VELatLong(latitude, longitude));

}

// On Change View Event

function OnChangeView() {

if (map.IsBirdseyeAvailable())

document.getElementById('birdsEyeBtn').disabled = false;

else

document.getElementById('birdsEyeBtn').disabled = true;

}

// Change Map style view

function ChangeStyle() {

var style = document.getElementById('mapStyle').getAttribute('value');

if (style == null)

style = document.getElementById('mapStyle').value;

map.SetMapStyle(style);

}

// Get and Validate Data to search

function FindWhatWhere() {

var what = document.getElementById('what').value;

var where = document.getElementById('where').value;

var index = 0;

if (what == "Search for a business or category")

what = "";

if (where == "Enter city, address, or landmark")

where = "";

alert("What = " + what + " Where = " + where);

if (what == "" && where == "") {

alert("Please Enter to Search and then click Find button");

} else {

FindItem(what, where, index);

}

}

// Find

function FindItem(what, where, index){

try {

map = new VEMap('mymap');

map.LoadMap();

// map.Find(what,where,null,null,index,20,true,true,false,true, ResultsFound); // // It searches & takes the map back to default map

map.FindLocation(where, ResultsFound);

alert("Find executed");

} catch(err) {

var txt = "Error executing Find \n Error: " + err.description;

alert (txt);

}

}

// Find Callback

function ResultsFound(results) {

if (results == null)

alert ("Results are Null");

else if (results.length <= 0)

alert("Results is ZERO");

else

alert("Results Found = ");

VEMap.IncludePointInView(map.GetCenter());

var pindid = 1;

var pin = new VEPushpin (pinID, map.GetCenter(), null, "John's office", "Building 28");

map.AddPushpin(pin);

pinID++;

alert("Added");

// results += "\n These are the Results Found.";

// ResultsPanel.Controls.Add(results.length);

// DoAlert(results.length);

}

I enter stuff like, "Mumbai, India", "New York". This code shows me "What = where ="Mumbai, India", "Find Executed", takes the map to Mumbai & "Results are Null" & the map returns on original map.

It would be nice if you can help me out with this code to get the problem in it. Along with this Find, can u guide to add pushpins on multiple search. And how to deal with search by category, Local info, etc.

I would appreciate your help. Please help me out. I can't believe my Driving Directions are working v. well in 1st time but this simple Find takes a hell of time.

Thanks

Trupti Dalia





Re: Problems Finding Info

Derek Chan


Trupti,

Your using an old VE4.0 way of consuming the callback. It's not the same with VE5.0, and there's documentation here that tells you how to deal with your results:

http://msdn2.microsoft.com/en-us/library/bb429645.aspx

In particular, you'll want to look at this part:

Return Value

This method returns nothing. The callback contains the following:

So this means that your callback looks something like this:

function onFoundResults(ShapeLayer,FindResult,Place,HasMore)
{
//do what you need with it
}


In this case, you'll likely find the VEFindResult and VEPlace the most useful returned objects to manipulate.






Re: Problems Finding Info

T V D

Thanks Derek for this reference. After I calling the new Find method with the callback u showed, I get this error

Invalid postback or callback argument. Event validation is enabled using in configuration or in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Invalid postback or callback argument. Event validation is enabled using in configuration or in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentException: Invalid postback or callback argument. Event validation is enabled using in configuration or in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.]
  System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument) +358
  System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument) +108
  System.Web.UI.HtmlControls.HtmlButton.RaisePostBackEvent(String eventArgument) +32
  System.Web.UI.HtmlControls.HtmlButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
  System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
  System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
  System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4918

Code Snippet

function FindItem(what, where, index){

try {

map = new VEMap('mymap');

map.LoadMap();

map.Find(what,where,null,null,index,20,true,true,true,true, ResultsFound); // // It searches & takes the map back to default map

alert("Find executed");

} catch(err) {

var txt = "Error executing Find \n Error: " + err.description;

alert (txt);

}

}

function ResultsFound(ShapeLayer, FindResults, Place, HasMore ) {

if (ShapeLayer != null)

alert ("ShapeLayer is their");

if (FindResults != null)

alert("Find Results is their");

if (Place != null)

alert("Place Found = ");

if (HasMore)

alert("HasMore Records");

// results += "\n These are the Results Found.";

// ResultsPanel.Controls.Add(results.length);

// DoAlert(results.length);

}

Now the exception is thrown after Find Executed alert. In the code, the above result is with useDefaultDisambiguation is set to true. When it is set to false, it shows Place found & then this error msg.

Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

I believe I need to register the callback. How do I do that. And how to show the pins and the location. Please help me at the earliest.

Thanks

Trupti