Solved

finding latitude and longitude using yahoo maps API in Flash

Posted on 2006-11-15
12
382 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
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 what frame rate is, how to control it and what effect it has on the video.

733 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