Solved

finding latitude and longitude using yahoo maps API in Flash

Posted on 2006-11-15
12
380 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
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…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.

809 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