Dinos
unread,May 12, 2011, 6:59:08 AM5/12/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Google Maps JavaScript API v3
Hi,
I am making a map in which I want to hide or to show markers when some
checkboxes are checked or not.
The data are loaded from a database with the use of an xml file.
I didn't find something how to do this (show/hide) for v3, so I
decided to try something by myself.
It works, but I am not satisfied by the way it is coded and I would
also like to work better and I will explain what I mean.
Every time that I click a checkbox I have an onclick call to the
initialize() function. Due to this if I have zoomed in the map and
click a checkbox it returns the map with the right data but of course
in the initial zoom.
Now about the code:
jQuery.get("data.xml", {}, function(data) {
jQuery(data).find("marker").each(function() {
var marker = jQuery(this);
var putIt = false;
//checkboxes
var cat_paper = document.getElementById("cat-paper").checked;
var cat_glass = document.getElementById("cat-glass").checked;
var cat_plastic = document.getElementById("cat-plastic").checked;
var cat_aluminium = document.getElementById("cat-
aluminium").checked;
var cat_general = document.getElementById("cat-general").checked;
var latlng = new
google.maps.LatLng(parseFloat(marker.attr("lat")),
parseFloat(marker.attr("lng")));
if(cat_paper && marker.attr("paper") == "1"){
putIt = true;
}
if(cat_glass && marker.attr("glass") == "1"){
putIt = true;
}
if(cat_plastic && marker.attr("plastic") == "1"){
putIt = true;
}
if(cat_aluminium && marker.attr("aluminium") == "1"){
putIt = true;
}
if(cat_general && marker.attr("packet") == "1"){
putIt = true;
}
if(putIt){
var marker = new google.maps.Marker({position: latlng, map:
map});
}
});
The above code works but it seems to me a bit ugly... Could you
propose me something? Also about the first question is there a way to
keep the current zoom? I would appreciate even negative answers.
Sometimes it saves you a lot of time to know that there is no solution
for a problem.
Kind regards,
Dinos