Hi, javascript newbie here....
I'm working with the excellent example here:
http://code.google.com/apis/maps/articles/phpsqlgeocode.html
I am building my xml file based on user submitted parameters. I would
like to show the count of markers returned as well as "no addresses
for your criteria" if results are zero.
Could someone provide an example of how to return the number/count of
the markers?
Thanks in advance for any help offered!
Here is my code:
// Get zip code from user
function getZipFromUrl( name ) {
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}
function showAddress(address) {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
geocoder = new GClientGeocoder();
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.setMapType(G_HYBRID_MAP);
map.setCenter(new GLatLng(36.16693,-86.784439), 10);
// Show jquery loading message...
$("div.loading").addClass("showLoading");
// Build url to xml file
var zipparam = getZipFromUrl( 'zipCriteria' );
GDownloadUrl("http://jis04951-4.jis.org/portal/pls/portal/
PORTAL.CRIMEMAPSBYZIP.show?p_arg_names=zip_code&p_arg_values=" +
zipparam, function(data) {
var xml = GXml.parse(data);
var markers =
xml.documentElement.getElementsByTagName("marker");
//Remove loading message
$("div.loading").removeClass("showLoading");
$("span.loadingMessage").addClass("hideLoading");
for (var i = 0; i < markers.length; i++) {
var address = markers[i].getAttribute("address");
var charge = markers[i].getAttribute("charge");
var name = markers[i].getAttribute("name");
var caseIdentifier =
markers[i].getAttribute("caseIdentifier");
addMarkerAtGeocode(address,name,charge,caseIdentifier)
}
function
addMarkerAtGeocode(address,name,charge,caseIdentifier) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
document.getElementById('notFound').innerHTML += address +
"<br/> ";
} else {
var marker = createMarker(point, name,
address, charge,
caseIdentifier);
map.addOverlay(marker);
}
}
);
}
});
}}
function createMarker(point, name, address, charge,
caseIdentifier)
{
var marker = new GMarker(point);
var html = "<b>" + name + "</b> <br/>" + address + "<br/>" +
charge
+ "<br/><a href='http://jis04951-4.jis.org/portal/pls/portal/
PORTAL.CASESEARCHDEFENDANTNAMEPUBDIST.show?
p_arg_names=a1&p_arg_values=" + caseIdentifier + "'
target='_blank'>Click here for case information & criminal
history....</a>";
GEvent.addListener(marker, 'click', function() {
marker.openInfoWindowHtml(html);
});
return marker;
}
--
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-api?hl=en.