Toggle Markers on and off with a checkbox

1,601 views
Skip to first unread message

gmapsNovice

unread,
May 23, 2011, 3:12:17 AM5/23/11
to google-map...@googlegroups.com
I'm building a map in which the user can view numerous architectural buildings based on the page/category they are in. The user can browse by location, architect name, style, type etc. 

What i want to do is to have a checkbox or link that when checked/pressed all the buildings that are stored on the database will show on the current map the user is at. 

I've looked all over the place including the gmaps docs and i can't find any examples relevant to what i'm doing. Has anyone done something like that this before that can help me understand how i can implement it. 

Thanks

en4ce

unread,
May 23, 2011, 4:08:59 AM5/23/11
to Google Maps JavaScript API v3
you need to send a ajax request to the server, execute your script
that gives you all markers within your needs and 2 js function, 1 for
"erase" all markers on the map and 1 for print all markers to the map

Chris Broadfoot

unread,
May 23, 2011, 6:45:38 AM5/23/11
to google-map...@googlegroups.com
Something like this perhaps?
--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.



--
http://twitter.com/broady

gmapsNovice

unread,
May 23, 2011, 2:46:03 PM5/23/11
to google-map...@googlegroups.com
I've looked at that sample already, the only problem i'm having with that is that that sample shows how to display them based on category that is given to the marker. 

The way my markers work are that they are displayed based on an ID that i give them when they are added tot he DataBase as well as a radius that is calculated based on their IP address. 

Pete Wingard

unread,
May 23, 2011, 3:12:16 PM5/23/11
to google-map...@googlegroups.com
I copied the example exactly and ran it on my site using firefox and selected don't allow and the same problem shows there too
see http://s.ocial.ly/public/new/locate_browser2.php

<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API v3 Example: Map Geolocation</title>
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript" src="http://code.google.com/apis/gears/gears_init.js"></script>
<script type="text/javascript">

var initialLocation;
var siberia = new google.maps.LatLng(60, 105);
var newyork = new google.maps.LatLng(40.69847032728747, -73.9514422416687);
var browserSupportFlag =  new Boolean();
var map;
var infowindow = new google.maps.InfoWindow();
 
function initialize() {
  var myOptions = {
    zoom: 6,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
 
  // Try W3C Geolocation method (Preferred)
  if(navigator.geolocation) {
    browserSupportFlag = true;
    navigator.geolocation.getCurrentPosition(function(position) {
      initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
      contentString = "Location found using W3C standard";
      map.setCenter(initialLocation);
      infowindow.setContent(contentString);
      infowindow.setPosition(initialLocation);
      infowindow.open(map);
    }, function() {
      handleNoGeolocation(browserSupportFlag);
    });
  } else if (google.gears) {
    // Try Google Gears Geolocation
    browserSupportFlag = true;
    var geo = google.gears.factory.create('beta.geolocation');
    geo.getCurrentPosition(function(position) {
      initialLocation = new google.maps.LatLng(position.latitude,position.longitude);
      contentString = "Location found using Google Gears";
      map.setCenter(initialLocation);
      infowindow.setContent(contentString);
      infowindow.setPosition(initialLocation);
      infowindow.open(map);
    }, function() {
      handleNoGeolocation(browserSupportFlag);
    });
  } else {
    // Browser doesn't support Geolocation
    browserSupportFlag = false;
    handleNoGeolocation(browserSupportFlag);
  }
}

function handleNoGeolocation(errorFlag) {
  if (errorFlag == true) {
    initialLocation = newyork;
    contentString = "Error: The Geolocation service failed.";
  } else {
    initialLocation = siberia;
    contentString = "Error: Your browser doesn't support geolocation. Are you in Siberia?";
  }
  map.setCenter(initialLocation);
  infowindow.setContent(contentString);
  infowindow.setPosition(initialLocation);
  infowindow.open(map);
}
</script>
</head>
<body onload="initialize()">
  <div id="map_canvas"></div>

</body>
</html>

On Mon, May 23, 2011 at 2:46 PM, gmapsNovice <svgm...@gmail.com> wrote:
I've looked at that sample already, the only problem i'm having with that is that that sample shows how to display them based on category that is given to the marker. 

The way my markers work are that they are displayed based on an ID that i give them when they are added tot he DataBase as well as a radius that is calculated based on their IP address. 

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



--
Pete
netl...@gmail.com

gmapsNovice

unread,
May 25, 2011, 6:33:33 AM5/25/11
to google-map...@googlegroups.com, netl...@gmail.com
Thanks for that,

i don't think that's what i need. That example simply grabs the location of a user. I already have that implemented. 
Reply all
Reply to author
Forward
0 new messages