Hi everyone,

As the subject states, I'm sure the answer to this is on a super noob
level - I'm just not exactly sure what I should be looking for here.

I'm trying to plot points on a Google map using hcard information in
my html.  This part is working very nicely thanks to Simon Willison,
however getting the code to add driving directions into the little
popup marker bubble has been a little trickier.  Thankfully, Mike
Williams is a Google maps API monster with tons of tutorials, so I was
able to snap up some of his code to patch into mine as well.

So far everything is working, but whenever I click the "To Here" or
"From here" direction links, they should be triggering the "tohere"
and "fromhere" functions, but instead they do nothing.  Any chance
someone could point me in the right direction with calling these
functions from those links?

here's the code:

jQuery(function($) {
    var themap = $('<div id="map-container"></div>').css({
        'width': '90%',
        'height': '400px'
    }).insertAfter('.vcard');

        if (GBrowserIsCompatible()) {
                var map = new GMap2(document.getElementById('map-container'));

                map.setCenter(new GLatLng(38.896422, -77.0332133), 13);
                map.addControl(new GSmallMapControl());
                var gmarkers = [];
                  var htmls = [];
                  var to_htmls = [];
                  var from_htmls = [];
                  var i=0;
        }

    // Geocode each hcard and add a marker
    $('.vcard').each(function() {
        var hcard = $(this);
        var latitude = hcard.find('.geo .latitude').text();
        var longitude = hcard.find('.geo .longitude').text();
                var name = hcard.find('.org').text();
                var street = hcard.find('.street-address').text();
                var extended = hcard.find('.extended-address').text();
                var locality = hcard.find('.locality').text();
                var region = hcard.find('.region').text();
                var postalcode = hcard.find('.postal-code').text();
        var point = new GLatLng( latitude,longitude);
        var marker = createMarker(point,'Elm Street','Some stuff to
display in the<br>First Info Window <br>With a <a href="http://
www.econym.demon.co.uk">Link<\/a> to my home page')
                map.addOverlay(marker);
    });
        // A function to create the marker and set up the event window
          function createMarker(point,name,html) {
            var marker = new GMarker(point);

            // The info window version with the "to here" form open
            to_htmls[i] = html + '<br>Directions: <b>To here<\/b> - <a
href="javascript:fromhere(' + i + ')">From here<\/a>' +
               '<br>Start address:<form action="http://maps.google.com/maps";
method="get" target="_blank">' +
               '<input type="text" SIZE=40 MAXLENGTH=40 name="saddr"
id="saddr" value="" /><br>' +
               '<INPUT value="Get Directions" TYPE="SUBMIT">' +
               '<input type="hidden" name="daddr" value="' + point.lat() +
',' + point.lng() +
                      // "(" + name + ")" +
               '"/>';
            // The info window version with the "to here" form open
            from_htmls[i] = html + '<br>Directions: <a href="javascript:tohere
(' + i + ')">To here<\/a> - <b>From here<\/b>' +
               '<br>End address:<form action="http://maps.google.com/maps";
method="get"" target="_blank">' +
               '<input type="text" SIZE=40 MAXLENGTH=40 name="daddr"
id="daddr" value="" /><br>' +
               '<INPUT value="Get Directions" TYPE="SUBMIT">' +
               '<input type="hidden" name="saddr" value="' + point.lat() +
',' + point.lng() +
                      // "(" + name + ")" +
               '"/>';
            // The inactive version of the direction info
            html = html + '<br>Directions: <a href="javascript:tohere('+i
+')">To here<\/a> - <a href="javascript:fromhere('+i+')">From here<\/
a>';

            GEvent.addListener(marker, "click", function() {
              marker.openInfoWindowHtml(html);
            });
            gmarkers[i] = marker;
            htmls[i] = html;
            i++;
            return marker;
          }

          // functions that open the directions forms
          function tohere(i) {
            gmarkers[i].openInfoWindowHtml(to_htmls[i]);
          }
          function fromhere(i) {
            gmarkers[i].openInfoWindowHtml(from_htmls[i]);
          }


});

Reply via email to