Solved

finding latitude and longitude using yahoo maps API in Flash

Posted on 2006-11-15
12
379 Views
Last Modified: 2008-01-09
I'm using flash with yahoo maps API and am trying to utilize a basic onClick command to get the lat/lon coordinate of the area clicked.

Using google maps I can use this:
//------------------------------------------------------------------
var eventListener = new Object();
eventListener.click = function (evnt){
trace("User clicked the map x:" + evnt.lat + " y:" + evnt.lng);
}
myMap.addEventListener("click", eventListener);
//------------------------------------------------------------------

I cant seem to replicate it using yahoo maps though ?
I've tried using the same example as above, but it doesnt work.

I've tried to implement this:
myMap.addEventListener (com.yahoo.maps.api.flash.YahooMap.EVENT_ONCLICK, onInitMap);

But I dont know the syntax to find the onClick event for EVENT_ONCLICK ?

Anyone know ?

Cheers

0
Comment
Question by:oneLi
  • 8
  • 4
12 Comments
 
LVL 11

Expert Comment

by:ch2
ID: 17947540
removed var. Try now.

eventListener = new Object();
eventListener.click = function (evnt){
trace("User clicked the map x:" + evnt.lat + " y:" + evnt.lng);
}
myMap.addEventListener("click", eventListener);
0
 
LVL 11

Expert Comment

by:ch2
ID: 17947651
Also i've seen an error. The evt is the event passed to the function not the object.

You're traying to trace "clic.lat" and guess you want myMap.lat

Try this.

eventListener = new Object();
eventListener.click = function (evt){
trace("User clicked the map x:" + myMap.lat + " y:" + myMap.lng);
}
myMap.addEventListener("click", eventListener);
0
 

Author Comment

by:oneLi
ID: 17947715
That method works fine using google maps...

Doesnt work when using yahoo maps in flash.

I've tried your suggestion but it still doesnt work, it doesnt see the eventListener at all ? It wont trace...

Do you know the syntax for getting the lat / lon coordinates from yahoo maps ?

I can attach a button function to the maps like this:

myMap.onPress = function  () {
            trace("clicked map");//works so map is being clicked
            trace("onCLick: " + myMap.onClick(eventData.lat)); //returns undefines so need to get corrcet syntax
            
      }



but have no idea of the correct synatx to get the Lat / Lon ?



but have no way to find the lat / lon
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 11

Expert Comment

by:ch2
ID: 17974154
The next example will trace lat and lon every time users move the map.



// Import API
import com.yahoo.maps.LatLon;
import com.yahoo.maps.tools.PanTool;
// Add listeners
myMap.addEventListener(com.yahoo.maps.api.flash.YahooMap.EVENT_INITIALIZE, onInitMap);
myMap.addEventListener(com.yahoo.maps.api.flash.YahooMap.EVENT_MOVE, onMapMove);
// Init fucntion
function onInitMap(eventData) {
      var pantool = new PanTool();
      myMap.addTool(pantool, true);
      var eventListener = new Object();
      var points = myMap.getCenter();
      convert(points);
}
// Convert points to LatLon
var _latlon:Object;
function convert(points:Object) {
      _latlon = new LatLon(points.lat, points.lon);
      trace(_latlon);
}
// Move function
function onMapMove() {
      var points = myMap.getCenter();
      convert(points);
}

http://developer.yahoo.com/flash/howto-maps_as2.html
0
 

Author Comment

by:oneLi
ID: 17974191
cheers for the example.
Is there anyway to get the LatLon value dependent on where you "click" on the map ?
That's what I'm really after...

It looks like I've made this event up ?
myMap.addEventListener (com.yahoo.maps.api.flash.YahooMap.EVENT_ONCLICK, onInitMap);

doesnt seem to exist !



0
 
LVL 11

Expert Comment

by:ch2
ID: 17974223
myMap.addEventListener(com.yahoo.maps.api.flash.YahooMap.EVENT_ONCLICK, onMapMove);

the above should work, if it dosen't download the last API here

http://developer.yahoo.com/maps/flash/componentEULA.html
0
 
LVL 11

Expert Comment

by:ch2
ID: 17974228
Copy paste this code and then should work:

// Import API
import com.yahoo.maps.LatLon;
import com.yahoo.maps.tools.PanTool;
// Add listeners
myMap.addEventListener(com.yahoo.maps.api.flash.YahooMap.EVENT_INITIALIZE, onInitMap);
myMap.addEventListener(com.yahoo.maps.api.flash.YahooMap.EVENT_ONCLICK, onMapClick);
// Init fucntion
function onInitMap(eventData) {
     var pantool = new PanTool();
     myMap.addTool(pantool, true);
     var eventListener = new Object();
     var points = myMap.getCenter();
     convert(points);
}
// Convert points to LatLon
var _latlon:Object;
function convert(points:Object) {
     _latlon = new LatLon(points.lat, points.lon);
     trace(_latlon);
}
// Move function
function onMapClick() {
     var points = myMap.getCenter();
     convert(points);
}
0
 

Author Comment

by:oneLi
ID: 17974249
now the onclick works BUT it always returns the center point of the map (myMap.getCenter();)
what I'm after is to return the LatLon of the point you actually click on the map... is that possible ?

0
 
LVL 11

Expert Comment

by:ch2
ID: 17974435
true, thought you could change it, sorry.

Use like this.

// Import API
import com.yahoo.maps.LatLon;
import com.yahoo.maps.tools.PanTool;
// Add listeners
myMap.addEventListener(com.yahoo.maps.api.flash.YahooMap.EVENT_INITIALIZE, onInitMap);
myMap.addEventListener(com.yahoo.maps.api.flash.YahooMap.EVENT_ONCLICK, onMapClick);
// Init fucntion
function onInitMap(eventData) {
      var pantool = new PanTool();
      myMap.addTool(pantool, true);
      var eventListener = new Object();
      var points = myMap.getCenter();
      convert(points);
}
function onMapClick(evt) {
      // Lat Lon position
      trace(evt.latlon);
      // Flash local position
      trace(evt.local);
      // Taken action
      trace(evt.action);
      //
      // Should trace something like this:
      //
      //point(-92.68505859375, 44.2483471498444)
      //point(260.475021362305, 82.4999313354492)
      //singleClick
}

Also i recommend you to read the documentation which is here: http://developer.yahoo.com/maps/flash/V3.04/flashReference.htm
0
 
LVL 11

Accepted Solution

by:
ch2 earned 500 total points
ID: 17974437
Better like this, i removed some code that is not needed.

// Import API
import com.yahoo.maps.LatLon;
import com.yahoo.maps.tools.PanTool;
// Add listeners
myMap.addEventListener(com.yahoo.maps.api.flash.YahooMap.EVENT_INITIALIZE, onInitMap);
myMap.addEventListener(com.yahoo.maps.api.flash.YahooMap.EVENT_ONCLICK, onMapClick);
// Init fucntion
function onInitMap(eventData) {
      var pantool = new PanTool();
      myMap.addTool(pantool, true);
}
function onMapClick(evt) {
      // Lat Lon position
      trace(evt.latlon);
      // Flash local position
      trace(evt.local);
      // Taken action
      trace(evt.action);
      //
      // Should trace something like this:
      //
      //point(-92.68505859375, 44.2483471498444)
      //point(260.475021362305, 82.4999313354492)
      //singleClick
}
0
 

Author Comment

by:oneLi
ID: 17974450
now that's it !

good stuff... that link seems broken though I get a 404 ?

Cheers for all the help

0
 
LVL 11

Expert Comment

by:ch2
ID: 17974460
Try start from here start from http://developer.yahoo.com/maps/flash/

nice it helped.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question