On 29 June 2011 16:08, Arnaud <[email protected]> wrote:
> Ok thank you, I will try that. Sounds good.
>
>
> On 29.06.11 15:24, "Pil" <[email protected]> wrote:
>
>>This should work (untested pseudocode):
>>
>>function createMarker(id) {
>>
>>  var marker = new google.maps.Marker({
>>    position: latlng,
>>    icon: image,
>>    map: map,
>>    title: name,
>>    draggable: true,
>>    id: id
>>   });
>>  gmarkers.push(marker);
>>}
>>
>>Now it should be possible to access every marker in gmarkers array by
>>its id:
>>
>> for (var i = 0; i < gmarkers.length; i++) {
>>  if (gmarkers[i].id == someid) {
>>    // do soemthing with your specific marker
>>  }
>> }
>>
>>
>>
>>On Jun 29, 12:21 pm, MrUpsidown <[email protected]> wrote:
>>> Hi
>>>
>>> Within a function, I create several markers and I need to assign them
>>> a specific ID.
>>>
>>>                 var marker = new google.maps.Marker({
>>>                     position: latlng,
>>>                     icon: image,
>>>                     map: map,
>>>                     title: name,
>>>                     draggable: true
>>>                 });
>>>
>>>                 marker.myid = markerid;
>>>
>>>                 gmarkers.push(marker);
>>>
>>> Now I have another function from which I want to 'click' a link that
>>> contains the marker id and fire a click event
>>>
>>>             function spotClick(markerId) {
>>>
>>>                 google.maps.event.trigger(gmarkers[markerId],"click");
>>>
>>>             }
>>>
>>> This obviously does not work. How am I supposed to refer to marker by
>>> the ID I assigned to it earlier?
>>>
>>> Thanks in advance!
>>
>>--
>>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
>>[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-js-api-v3?hl=en.
>>
>
>
> --
> 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 [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-js-api-v3?hl=en.
>
>

I have a similar need. I'd like to be able to open a map, add a load
of markers (the position of vehicles performing certain duties).

I have a mechanism to periodically get the lastest data and to update
the positions of the vehicles.

Based upon the example code that Pil provided, I think I can get that
bit all working.

I can handle a new vehicle (vehicles go on and off jobs, so as a
vehicle goes on job it appears on the map).

The part I can't seem to do is to deal with a vehicle that goes off job.

I think ...

var marker = new google.maps.Marker(...);

could be ...

var singleMarker = {
 id: 'this_markers_id',
 lastUpdated : Date.now(),
 marker : new google.maps.Marker(...)
};

myMarkers.push(singleMarker);

Ideally, I'd like to use the ID as a key (like in an associative array).

So, maybe ...

myMarkers['this_markers_id'] = singleMarker;

Does this sound feasible?



-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

-- 
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 [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-js-api-v3?hl=en.

Reply via email to