[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

finding latitude and longitude using yahoo maps API in Flash

Posted on 2006-11-15
12
Medium Priority
?
388 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

656 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