Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

Can I add a time limit to markers - Google Maps API

Hi,

I am working on a project, using the Google Maps API. I have markers, set up around the map and was wondering if it was possible to set a 'time limit' for them? Basically, I want a marker to be added, and be removed automatically after a set time. Is this possible?

Regards, Ryan

1 Answer

I don't know google maps API has that function included. But you can simulate marker by creating your custom overlay that looks like a marker (https://developers.google.com/maps/documentation/javascript/overlays?csw=1).

I think there are way you can set time limit using javascript or Jquery. You might have write a function to that show and hide markers. Have the javascript setTimeout( function name, time) or use anonymous function with codes in it.

ex. => window.setTimeout( function, delay);

Jquery might be simpler solution where can do work with a combination of using $('.marker') concatenated with fadeIn( ) and fadeOut, show( ) and hide( ).

Something like => var myTimeoutMarker = $('#map_canvas img[src*="a_marker_icon"][class!="timeoutMarker"]').fadeOut(5000); //Fades out in 5 seconds.

I hope this can at least give you some lead or possible strategy that may work. Good luck.

Hey,

Cheers, much appreciated. I will give it a go!

Reagrds, Ryan