example can be found at:
http://projects.snowshtechnologies.com/findhrr/_admin/_geolocate/content.php
view the source for the full idea.
I am trying to get the JS to populate the long/lat fields as soon as a text search result has re-positioned the map.
The linked Map script has a submit feature which returns the long lat back to a parent form (not included in this link – so don’t worry about that!)
There are two main methods here:
First is the text search – which is used to determine the map location buy entering an address. The required fix lies here, after the user clicks search, the map returns the position – all good. But I also now need the long/lat to appear in the text areas and enable the submit button.. you can see that functionality in the next method:
The second method simply allows the user to drag the map, the last clicked position will populate the lon/lat fields.
The txt search function:
function FindLoc(numResults)
{
try
{
results = map.Find(document.getElementById('txtWhat').value,
document.getElementById('txtWhere').value,
null,
null,
index,
numResults,
true,
true,
true,
true,
MoreResults);
index = parseInt(index)+9;
}
catch(e)
{
alert(e.message);
}
map.AttachEvent("onchange", DisplayCoords);
}
I have a function displayCoords that will output the clicked long/lat position to the page, I have included it in the text search function but no joy.
map.AttachEvent("onchange", DisplayCoords);
Any ideas?
I can’t change your sources so I can’t test this to be sure, however, I believe you want to do the following:
1) Get rid of the “map.AttachEvent” in FindLoc, because this will attach a new event each time the user performs a find, and anyway it’s not a correct event name for the map type so it won’t be triggered. The list of valid events is here.
2) Change your MoreResults callback so that it reads the resultsArray parameter, which is an array of find results, and reads the LatLong property from an array element. This class is documented here. For example, something like:
Edit: The resultsArray always seems to be null, so you need to use the places array instead. Add this to the beginning of MoreResults:
I tested this alternative, and it does work for me.