Solved

finding latitude and longitude using yahoo maps API in Flash

Posted on 2006-11-15
12
377 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 11

Expert Comment

by:ch2
Comment Utility
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
Comment Utility
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
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 11

Expert Comment

by:ch2
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Try start from here start from http://developer.yahoo.com/maps/flash/

nice it helped.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
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…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now