Thursday, May 3, 2012

[Google Maps API v2] Re: map page with geocoding not working as expected.

On May 3, 10:36 pm, jiminwoodstock <jiminwoodst...@gmail.com> wrote:
> The link to my site with the map page iswww.jimbell.us/testmap2a.html
>
> Apparently, the callback function from the geocoder getLocations
> function does not hold up the execution of the following code.

This is entirely right, and your diagnosis is spot-on.

What it means is that if you want to use the data provided by the
geocoder, everything needs to be done inside the callback function.
You can't get at the data outside that function (not without
acrobatics, anyway).

That means that this line
document.getElementById("side_bar").innerHTML =
side_bar_html;
is in the wrong place, as you surmised.

However you create side_bar_html in your createMarker() function,
here:
side_bar_html += '<a href="javascript:myclick(' +
(gmarkers.length-1) + ')">' + name + '<\/a><br>';
so just create the sidebar there instead. Replace that line with
document.getElementById("side_bar").innerHTML +=
'<a href="javascript:myclick(' + (gmarkers.length-1) + ')">' +
name + '<\/a><br>';

Some of those lines will have wrapped in the groups interface.

It doesn't matter if you don't remove the first line I've quoted here
-- but you don't need it. You should ensure that the element's
innerHTML is empty, though, before you start using it.

Note: it's **very** bad practice to geocode addresses you know about
in advance. You should have found their locations yourself and written
those locations into your page. Geocoding should be reserved for
addresses you cannot know or plan for, which is basically what your
site visitors enter. However, as an exercise in asynchronous
operations, this is fine (and you have recognised what's going on,
which many don't).

--
You received this message because you are subscribed to the Google Groups "Google Maps API V2" group.
To post to this group, send email to google-maps-api@googlegroups.com.
To unsubscribe from this group, send email to google-maps-api+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-api?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate