Comunidad de diseño web y desarrollo en internet online

google maps y as3

Citar            
MensajeEscrito el 15 Sep 2010 04:22 pm
hola amigos de cristalab, estoy utilizando google maps con flash y quisiera ver si alguien sabe como colocar un marcador al hacer un click en el mapa, busque en la api como capturar las coordenadas al hacer el evento pero no lo encontre, si tuvieran algun link que me pueda ayudar me serviria o el nombre de la funcion que hace eso, tambien si tienen un link en donde se utilice la version 3 tambien me ayudaria
Gracias

Por CLAnonimo

Claber

600 de clabLevel

5 tutoriales
1 articulo

 

Este es un usuario anónimo genérico para las cuentas borradas o perdidas.

chrome
Citar            
MensajeEscrito el 15 Sep 2010 06:20 pm
hola dantero!
a ver si esto es lo que necesitas...
primero agrégale un listener a tu "mapa" ( "mapa" sería la instancia de la clase "Map" del api), que se despache con un evento (con el CLICK en tu caso) del tipo "MapMouseEvent":

Código ActionScript :

...
mapa_mc.addEventListener(MapMouseEvent.CLICK, on_click_sobre_mapa);
...


ya en en método que llama el listener, el objeto que recibe por parámetro tiene una propiedad que es latitud y longitud (una propiedad que es una instancia de la clase "LatLng" del api) del punto donde el usuario acaba de cliquear:

Código ActionScript :

...
private function on_click_sobre_mapa(e:MapMouseEvent):void{
   var lt_lg:LatLng = LatLng(e.latLng);
   // resto del codigo
}
...

entonces luego de obtener esta latitud longitud utilizarás estos datos para crear un nuevo elemento en el mapa (por ejemplo un nuevo "Marker").

Para esto, bastaría agregar esto al método "on_click_sobre_mapa":

Código ActionScript :

...
var mi_marker:Marker = new Marker(lt_lg);
...


y por último agregar este marcador al mapa, usando el método addOverlay(de la clase "Map"):

Código ActionScript :

...
mapa_mc.addOverlay(mi_marker);
...


después de todo esto el método quedaría así:

Código ActionScript :

private function on_click_sobre_mapa(e:MapMouseEvent):void{
   var lt_lg:LatLng = LatLng(e.latLng);
   var mi_marker:Marker = new Marker(lt_lg);
   mapa_mc.addOverlay(mi_marker);
}


para personalizar un poco más las cosas, te recomiendo mires la documentación:
http://code.google.com/intl/es-ES/apis/maps/documentation/flash/reference.html#Map.addOverlay

Espero que te sirva!!

Saludos

Por CLAnonimo

Claber

600 de clabLevel

5 tutoriales
1 articulo

 

Este es un usuario anónimo genérico para las cuentas borradas o perdidas.

firefox
Citar            
MensajeEscrito el 15 Sep 2010 08:26 pm
Saludos

Me comento Debosotnas que necesitabas que al dar clic se cree un marker, en este codigo ademas de crear el marker imprime las coordenadas del ultimo marcador creado en un campo de texto, espero te sirva

hasta pronto

Código ActionScript :

//IMPORTAR LAS CLASES NECESARIAS
import com.google.maps.LatLng;
import com.google.maps.Map;
import com.google.maps.MapEvent;
import com.google.maps.MapType;
import com.google.maps.controls.*;
import com.google.maps.LatLng;
import com.google.maps.overlays.*;
import com.google.maps.MapMouseEvent;
import com.google.maps.InfoWindowOptions;

//DEFINE ANCHO Y ALTO DE LA PELICULA
var ANCHO:int = stage.stageWidth;
var ALTO:int = stage.stageHeight;

//CREA EL MAPA
var map:Map = new Map();

//SE CREA UNA VARIABLE TIPO MARKER PARA LOS MARCADORES
var marker:Marker;

//LA GOOGLE API KEY(LA DA GOOGLE)
map.key = "ABQIAAAAvvxprSVgDmort-nQvP9UOBRcIBM5SEgUYyuJIuqH4Qf0kgkYgBT_K4sLwopPkxZFAw-tlQLIRz3sTA";

//ANCHO Y ALTO DEL MAPA = A LOS DE LA PELI
map.setSize(new Point(ANCHO, ALTO));

//DETECTAR SI EL MAPA YA CARGO
map.addEventListener(MapEvent.MAP_READY, onMapReady);

//SE CARGA EL MAPA PARA LA VISUALIZACION
this.addChild(map);

//SE DEFINE EL CAMPO DE TEXTO Y SUS ATRIBUTOS PARA LAS COORDENADAS DEL CENTRO
var texto:TextField = new TextField();
var formatoTexto:TextFormat = new TextFormat();
this.addChild(texto);
formatoTexto.font = "arial";
formatoTexto.size = 12;
formatoTexto.align = TextFormatAlign.LEFT;
formatoTexto.bold = true;
texto.multiline = true;
texto.background = true;
texto.autoSize = TextFieldAutoSize.LEFT;
texto.defaultTextFormat = formatoTexto;

//SE DEFINE EL CAMPO DE TEXTO Y SUS ATRIBUTOS PARA LAS COORDENADAS DE LOS MARKERS
var texto1:TextField = new TextField();
var formatoTexto1:TextFormat = new TextFormat();
this.addChild(texto1);
formatoTexto1.font = "arial";
formatoTexto1.size = 12;
formatoTexto1.align = TextFormatAlign.RIGHT;
formatoTexto1.bold = true;
texto1.multiline = true;
texto1.background = true;
texto1.autoSize = TextFieldAutoSize.RIGHT;
texto1.defaultTextFormat = formatoTexto1;

//SI TODO SE CARGO OK EJECUTA
function onMapReady(event:Event):void {
    //CENTRAR EL MAPA, DEFINIR EL ZOOM Y EL TIPO DE MAPA
    map.setCenter(new LatLng(6.186255,-75.562156), 18, MapType.SATELLITE_MAP_TYPE);
    //MUESTRA EL CONTROL DE ZOOM
    map.addControl(new ZoomControl());
    //MUESTRA EL CONTROL DE POSICIÓN
    map.addControl(new PositionControl());
    //MUESTRA EL CONTROL DE TIPO DE MAPA
    map.addControl(new MapTypeControl());    
    //CREA UN MARKER
    marker=new Marker(new LatLng(6.186255,-75.562156));
    //Y LO AGREGA A LA VISUALIZACION DEL MAPA
    map.addOverlay(marker);
    //DEFINE LAS OPCIONES DEL MARKER
    var options:MarkerOptions =
    new MarkerOptions( { fillStyle: { color: 0x000080 }} );
    marker.setOptions(options);
    //HABILITA IMPRIMIR LAS COORDENADAS EN EL MAPA
    map.addEventListener(Event.ENTER_FRAME,coordenadas);
    //HABILITA LOS CLIC EN EL MAPA PARA CREAR UN MARKER Y MOSTRAR SUS COORDENADAS
    map.addEventListener(MapMouseEvent.CLICK,mapaClic);    
}
    //MUESTRA LAS COORDENADAS DEL CENTRO DEL MAPA
    function coordenadas(e:Event):void {
        texto.text = "Lat/Lng: "+e.currentTarget.getCenter()+"\rZoom: "+e.currentTarget.getZoom() ;
        texto.x = (ANCHO-texto.textWidth)-10;
        texto.y = (ALTO-texto.textHeight)-30;
    }
    //CREA UN MARKER Y MUESTRA SUS COORDENADAS
    function mapaClic(e:MapMouseEvent):void {
        //CREA UN MARKER Y LO UBICA EN LAS COORDENADAS DEL CLIC
        marker=new Marker(e.latLng);
        //LO AGREGA A LA VISUALIZACION DEL MAPA
        map.addOverlay(marker);
        //MUESTRA LAS COORDENADAS DEL MARKER CREADO EN EL CAMPO DE TEXTO PREPARADO ANTES
        texto1.text = "" + e.latLng;
        texto1.x = (ANCHO-texto.textWidth)-10;
        texto1.y = (ALTO-texto.textHeight)-60;
    }

Por CLAnonimo

Claber

600 de clabLevel

5 tutoriales
1 articulo

 

Este es un usuario anónimo genérico para las cuentas borradas o perdidas.

firefox
Citar            
MensajeEscrito el 15 Sep 2010 10:27 pm
eso es lo que buscaba, muchas gracias :cool:

Por CLAnonimo

Claber

600 de clabLevel

5 tutoriales
1 articulo

 

Este es un usuario anónimo genérico para las cuentas borradas o perdidas.

chrome

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.