Glad to help, Joe.
I didn't mean to imply that your coding was sloppy! I'm just an inveterate
tweaker. :-) I understand fully about taking shortcuts to get a prototype
running. (Just don't reload your page more than 100 times in a day!)
You know, now that I think of it, it would be pretty easy to modify your
code to create a JavaScript object with all the geocoded data in it - and
then you can paste that object back into the source code and remove the
gecoding logic. This would make your demo load quite a bit faster.
Something like this...
Add this tag to your HTML:
<pre id="geocoded"></pre>
And run this (untested) JS code:
jQuery(function( $j ) {
var offices = ['null'], nOffices = 150, nDone = 0;
var $map2 = $j('#map2');
$map2.jmap({
mapCenter:[30.2687,-97.7452],
mapZoom: 13
});
for( i = 1; i <= nOffices; i++ )
geocodeOffice( i );
function geocodeOffice( i ) {
$map2.jmap( "searchAddress",
{ address :$j('#address'+i).val() },
function( options, point ) {
offices[i] =
' { address:"' + address +
'", lat:' + point.y +
', lng:' + point.x + '}';
if( ++nDone == nOffices )
$j('#geocoded').html(
'var geocodedOffices = [\n' +
offices.join(',\n') +
'];\n'
);
}
);
}
}); // End of DOM Ready
After all the offices are geocoded, the PRE should be filled in with JS
source code for the 'geocodedOffices' array.
Copy and paste that result into your JS source code, and now your production
code can be:
jQuery(function( $j ) {
var nOffices = 150;
var $map2 = $j('#map2');
$map2.jmap({
mapCenter:[30.2687,-97.7452],
mapZoom: 13
});
for( i = 1; i <= nOffices; i++ )
createMarker( i );
function createMarker( i ) {
var office = geocodedOffices[i];
$map2.jmap("addMarker", {
pointLatLng: [ office.lat, office.lng ],
pointHTML: "<div style='width:200px;'>
This office is located
at:
<b>" + office.address + "
</div>",
centerMap: false
});
}
}); // End of DOM Ready
Maybe not necessary for your demo, but this is a pretty good trick for
anyone who is using the client geocoder and wants to cache a particular set
of locations without having to do any server coding.
-Mike
> From: Joe
>
> Mike,
>
> You are the man! No seriously! I fully understood WHY the
> comment bubble HTML was only using the last iteration's
> value, but I am no expert with closures. The book jQuery in
> Action touches on it, but I still haven't wrapped my head
> around its power. Thank you thank you thank you so much.
> Your explanation is clear, concise and elegant. I have
> tested it out and it works great
>
>
> As far as the coding practices are concerned, I am aware of
> all of the issues and whipped this together toward the end of
> the day yesterday and was determined to get it to work today.
> Also, I am using a portal solution that uses Velocity
> templates so the $ alias can't be used.
> And having to deploy the "theme" just to test in the
> development environment coerced me to use sloppy practices.
>
> In regards to the amount of queries to Google, I FULLY agree
> with storing these values on the server instead of the client
> doing the heavy lifting. I need to SHOW this in order for it
> to get accomplished, if you know what I mean.
>
> Thanks again!
>
> Joe
>
> On Apr 26, 11:53 am, "Michael Geary" <
M...@Geary.com>