On May 24, 2:19 pm, nlraley82 <[email protected]> wrote:
> When that dragend event occurs I want to retrieve the marker id, which I
> want to be the idFinish value for a Finish marker and an idStart value for a
> start marker.
>
> That make sense?
Not really.
There is an issue -- which is why it's FAR better to create an HTML
page we can run, because debugging is easier (you can then plug the
validated code into your C++ app). In this listener,
GEvent.addListener(ZoneStartFinishMarkers[idStart], "dragend",
function(){
// Creates the Listener for the StartMarker
var Point = StartMarker.getPoint(); // Gets the new location of the
marker
UpdateString = "S," + Point;
// Sets the update string to the new location - S indicates Start
} );
what is "StartMarker" when that function executes? It's not
necessarily the same as when the function was set up, and
StartMarker.getPoint() may not return what you expect.
That will really only be solved by using a single createMarker
function and passing in what you want to be tied to each marker. This
is called function closure -- you probably know that -- and is
explained in Mike's tutorial.
It is possible to something like marker.markerId=idStart and create a
custom property for the marker which you can refer to later. Don't use
two-letter properties because they may clash with the API's own
internal properties. This will also be subject to scope
considerations.
I would suggest something like the following, although this may not be
entirely equivalent to your code snippet:
function createMarker(point,options,type,index) {
// create local variable and assign a marker to it
var marker = new GMarker(point,options);
// define custom property of this particular marker
marker.markerId = index;
// add listener to this particular marker. Every local variable
inside
// the createMarker function is available in the listener and
// function closure ties everything together
GEvent.addListener(marker,"dragend", function () {
UpdateString = type + "," + this.getPoint();
// this.markerId will also be available
})
// Give the complete marker back to the calling context
return marker;
}
ZoneStartFinishMarkers[idStart] = createMarker(point1,
ZoneStartMarkerOptions, "S", idStart);
ZoneStartFinishMarkers[idFinish] = createMarker(point2,
ZoneFinishMarkerOptions, "F", idFinish);
--
You received this message because you are subscribed to the Google Groups
"Google Maps API" 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-api?hl=en.