On Nov 2, 3:23 pm, Kasper <
kaspervandel...@gmail.com> wrote:
> I have a map on my webpage, which works fine, but I want to add data to it
> after it has been initialized.
> The map that is showing, is a normal map, with about *20-30 custom* (static)
> * markers* on it.
>
> I would then like to add (*after 1 second*) a *marker* and a *polyline* to
> the map.
>
> But then, the map should update with that data (the first 20-30 custom
> markers, the new marker and the polyline), *every 30 seconds*.
>
> For refreshing the map, I could use a setInterval function to reinitialize
> the map every (for example) 5 seconds, but that doesnt work very well...
>
> So, these are my two main questions:
> *1. How do you add a marker to a map, after the map has been initialised?*
> I tried: setting the map variable as a global variable, and then setting
> the marker for map: map, but that doesnt work:
>
> var treinmarker = new google.maps.Marker({position: position, map: map,
>
> > title: 'Trein', icon: 'icon.png' });
Is your map variable global?
Please read and follow the posting guidelines and provide a link to
your map that exhibits the problem, not code.
>
> *2. How do I update the position of a marker, without having to refresh the
> complete map? (thus having to add the marker again)*
Example (using v2 but the concept is the same):
http://www.geocodezip.com/v2_volcanoBrowser.asp
The basic concept is AJAX:
The Basics - Part 11 The AJAX Philosophy
http://econym.org.uk/gmap/basic11.htm
(from Mike Williams' v2 tutorial, but the concepts apply to v3)
-- Larry