I'm confused as to how to get an argument from one function to another... or how to solve my issue here. When I run this, it throws a js error "marker is undefined". Anyone have any thoughts as to how I could get this loop to work? I'm trying to pass the info into the text "bubbles" that appear when you click on the marker.
PHP Code:var map = null;
var geocoder = null;
<?php
$key = 0;
foreach($results as $key => $contact) {
$results[$key][javavarname] = "address$key";
$varString = "var address$key = \"$contact[address1], $contact[city], $contact[state], $contact[zip]\";\n";
echo $varString;
$key++;
}
?>
function markAddress(address) {
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
// alert(address + " not found");
} else {
map.setCenter(point, 7);
var marker = new GMarker(point);
map.addOverlay(marker);
}
}
);
}
}
function load() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
geocoder = new GClientGeocoder();
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
<?
foreach($results as $contact) {
echo "markAddress(" . $contact[javavarname] . ");\n";
echo "GEvent.addListener(marker, \"click\", function() {\n";
echo "marker.openInfoWindowHtml(" . $contact[javavarname] . ");\n";
echo "});\n";
}
?>
}
}



Bookmarks