I am playing with the Yahoo Maps communication tool kit since it has released and I was pretty disappointed on seeing that it doesn’t had the CustomPoiMarkerClick event.
Then I started looking in the code which is relased by yahoo maps as a wrapper to the existing Flex 1.5 API
I have just modified the method in that source and i am posting it here so it might be useful to ppl working on Mashups.
function onPOIClicked(ev:Object) {
var rtnObj:Object = new Object();
var myMarker:Object = ev.marker;
for (var p in myMarker) {
rtnObj[p] = myMarker[p].toString();
}
for (var q in ev){
if (typeof(ev[q]) != 'movieclip') {
rtnObj[q] = ev[q];
}
}
EIBuffer.addCall({method:swfDomId + ".onPOIClicked" + id, data:rtnObj});
}
After changing the method in the as2map.fla file which is under source/as2 directory of yahoo library source.
I was able to get all the marker details like ‘title’, ‘description’,'index’ and the usual stuff like latlon information etc.
Hope that helps,
Anupam




The docs are weak in this regard. For the following, code how should the “ev” variable be referenced to get back the point of interest data?
private function onPOIClicked(ev:Object):void
{
title.text = ev.???;
}
What is the object reference supposed to be in this case above?
As a bonus, I have included below a snippet of something that should have been easy to figure out had the docs been more complete:
private function onMapClick(ev:MapEvent):void
{
var llpat:RegExp = /point\((.*)\,(.*)\)/i;
var rs:String;
var ro:Object;
rs = ev.lastResult.latlon;
if ( llpat.test(rs) == true )
{
ro = llpat.exec(rs);
selLatitude = ro[2];
selLongitude = ro[1];
latitudevalue.text = selLatitude.toString();
longitudevalue.text = selLongitude.toString();
var myMarker:Object = {index:’M!’, title:’My Mark’, description:’This is a marker!\nIt is located here.’, markerColor:0×999900, strokeColor:0xFF00FF};
latLonController.addMarkerByLatLon(‘CustomPOIMarker’, selLatitude, selLongitude, myMarker);
//latLonController.addMarkerByLatLon(”,selLatitude, selLongitude, {waypointIndex:’M'});
}
}
Note that there is probably a better way to access the latlon variable. I found no meaningful examples describing this.
Hi Mario,
Can you please elaborate more on this..
As per my understanding the following loop does the trick as title and all other information about point of interest data is stored in the marker object and you can get the marker object and all the properties of the marker object by this loop ..
for (var p in myMarker) {
rtnObj[p] = myMarker[p].toString();
}
So you will be able to get the latitude and longitude information using the rtnObj
Hope that Helps,
Regards,
Anupam
I was able to answer my own question for het POI issue. The answer to that was:
ev.lastResult.title
and
ev.lastResult.description
I wanted to know the dotted notation, rather then the generic array ref approach.
I still don’t know what the dotted notation for the latlon should be for an event such as:
ev.lastResult.latlon
The object type is “point”, but nowhere is it described that I was able to unearth. My solution for referencing it was dumb, but I was in a rush.
Thanks for your input.
Hey guys,
I’m using Flex 2, and trying to use Yahoo’s new AS3 Maps libraries. I am trying to place a marker on the map wherever and whenever a user clicks on the map. I am getting some strange behavior from the addMarkerByLatLon function. Hope you can help me out
Below is some of my code:
//these two lines are called when the map initializes
var d:MapEventDispatcher = new MapEventDispatcher(myAS2Map);
d.addEventListener(‘onClick’, onClick);
//this is my onClick function
private function onClick(ev:MapEvent):void{
var llc:LatLonController = new LatLonController(myAS2Map);
var point:Object = {latitude:ev.lastResult.latlon.x, longitude:ev.lastResult.latlon.y};
var latNum:Number = new Number(point.latitude);
var lonNum:Number = new Number(point.longitude);
llc.addMarkerByLatLon(‘WaypointMarker’, latNum, lonNum, ”);
Alert.show(“Lat: ” + point.latitude + ‘\n’ + “Lon: ” + point.longitude + ‘\n’ + “Latx: ” + ev.lastResult.latlon.x + ‘\n’ + “Lony: ” + ev.lastResult.latlon.y);
}
When a user clicks on the map, the alert displays the correct latlons.
The first time a user clicks on the map, a marker is placed, but only at the center. For any subsequent clicks on the map, the Alert displays the correct latlon but no marker is displayed!
What could I be missing? Your help would be much appreciated!
G
Thank you so much for this *minor* alteration! I’ve just finished trying everything I could to grab the title property, and was about to give up. It’s comforting to know the value wasn’t available in the first place
Thanks Thousand for your comment
Hi,
I’m making cyclingapplication in FLEX2.
I’m trying to add a marker by latlon on a map.
The latitude and longitudes are in a xml file (database driven).
this what it should be.
the truyth is that I can’t manage to add a markerby latlon on the map with de latlon given in the string.
–> latLonController.addMarkerByLatLon(“WaypointMarker”, 51.265960, 3.034449);
can someone help me with the code? can someone help me with adding an entire route with markers on a map?
please help
very interesting.
i’m adding in RSS Reader