GOOGLE MAPS API Y ADOBE AIR FOR ANDROID
GOOGLE MAPS API Y ADOBE AIR FOR ANDROID
Hice unas pruebas con la API de Google Maps funcionando en Adobe AIR for Android, la puedan descargar y probar, funciona bastante bien y muy rápido, el archivo “.apk” deben instalarlo, pero si abren los archivos y ejecutan el el fla deben agregar su “key” de google Maps y su “url” ingresada al momento de obtener su “key”. Saludos.
package com.pcornejo { import com.google.maps.MapOptions; import com.google.maps.services.Directions; import com.google.maps.services.DirectionsEvent; import com.google.maps.services.DirectionsOptions; import fl.controls.Button; import fl.controls.TextInput; import flash.display.MovieClip; import flash.events.Event; import flash.events.GeolocationEvent; import flash.events.MouseEvent; import flash.events.StatusEvent; import flash.events.TouchEvent; import flash.geom.Point; import flash.geom.Rectangle; import flash.net.dns.SRVRecord; import flash.sensors.Geolocation; import flash.text.TextField; import flash.ui.Multitouch; import flash.ui.MultitouchInputMode; import com.google.maps.LatLng; import com.google.maps.Map; import com.google.maps.MapEvent; import com.google.maps.MapType; import com.google.maps.overlays.Marker; /** * Main * @author Patricio Cornejo * http://www.pcornejo.com */ public class Main extends MovieClip { private const key:String = ""; // Obténla en http://code.google.com/intl/es-ES/apis/maps/signup.html private const url:String = ""; private const loc:String = "en"; //es - en - fr private const tpo:Number = 1000; private var map:Map; private var geo:Geolocation; private var ubi_btn:Button; private var dir_btn:Button; private var dir_ti:TextInput; private var bsc_btn:Button; private var sz:MovieClip; private var txt:TextField; private var ubi:Marker; private var dir:Directions; private var lat:Number = 0; private var long:Number = 0; private var ubi_activado:Boolean = false; private var dir_activado:Boolean = false; public function Main():void { addEventListener(Event.ADDED_TO_STAGE, configUI); } private function configUI(e:Event):void { txt = new TextField(); stage.addChild(txt); configGps(); removeEventListener(Event.ADDED_TO_STAGE, configUI); } private function configTouch():void { if (Multitouch.supportsTouchEvents) { Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT; } } private function configDir():void { var dir_opts:DirectionsOptions = new DirectionsOptions( { locale: loc } ); dir = new Directions(); dir.setOptions(dir_opts); dir.addEventListener(DirectionsEvent.DIRECTIONS_SUCCESS, dirOk); dir.addEventListener(DirectionsEvent.DIRECTIONS_FAILURE, dirFail); } private function configUbi():void { ubi = new Marker(new LatLng(0, 0)); ubi.visible = false; map.addOverlay(ubi); } private function configGps():void { if (Geolocation.isSupported) { configMap(); configTouch(); geo = new Geolocation(); geo.setRequestedUpdateInterval(tpo); geo.addEventListener(StatusEvent.STATUS, statusGeo); } else { // } } private function configMap():void { map = new Map(); map.key = key; map.url = url; map.setSize(new Point(stage.stageWidth, stage.stageHeight)); map.addEventListener(MapEvent.MAP_READY, onMapReady); this.addChild(map); } private function statusGeo(e:StatusEvent):void { // } private function updateGeo(e:GeolocationEvent):void { lat = e.latitude; long = e.longitude; if (ubi_activado) { ubi.visible = true; map.setCenter(new LatLng(lat, long), 14); ubi.setLatLng(new LatLng(lat, long)); } } private function dirFail(e:DirectionsEvent):void { dir_ti.text = "fail direccion"; } private function dirOk(event:DirectionsEvent):void { var dir:Directions = event.directions; dir_ti.text = "ok direccion"; map.clearOverlays(); map.addOverlay(dir.createPolyline()); map.setCenter(dir.bounds.getCenter(), map.getBoundsZoomLevel(dir.bounds)); map.addOverlay(new Marker(dir.getGeocode(0).point)); } private function onMapReady(e:Event):void { crearUbi(); configUbi(); configDir(); crearDir(); geo.addEventListener(GeolocationEvent.UPDATE, updateGeo); } private function crearDir():void { dir_btn = new Button(); dir_btn.width = dir_btn.height = 100; dir_btn.label = "Direction"; dir_btn.addEventListener(TouchEvent.TOUCH_TAP, verBarra); dir_btn.x = stage.stageWidth - dir_btn.width - ubi_btn.width - 30; dir_btn.y = stage.stageHeight - dir_btn.height - 20; addChild(dir_btn); } private function verBarra(e:TouchEvent):void { if (dir_activado) { dir_activado = false; dir_btn.label = "Direction"; removeChild(dir_ti); removeChild(bsc_btn); return; } else { dir_activado = true; dir_btn.label = "Disable"; } dir_ti = new TextInput(); dir_ti.width = 300; dir_ti.height = 60; dir_ti.x = 20; dir_ti.y = 100; addChild(dir_ti); dir_ti.text = "77 Massachusetts Avenue, Cambridge, MA to 4 Yawkey Way, Boston, MA 02215 (Fenway Park)"; bsc_btn = new Button(); bsc_btn.x = dir_ti.x + dir_ti.width + 10; bsc_btn.y = dir_ti.y; bsc_btn.width = 60; bsc_btn.height = 60; bsc_btn.label = "Search"; bsc_btn.addEventListener(TouchEvent.TOUCH_TAP, buscarDir); addChild(bsc_btn); } private function buscarDir(e:TouchEvent):void { dir.load(dir_ti.text); } private function crearUbi():void { ubi_btn = new Button(); ubi_btn.width = ubi_btn.height = 100; ubi_btn.label = "Ubication"; ubi_btn.addEventListener(TouchEvent.TOUCH_TAP, verUbicacion); ubi_btn.x = stage.stageWidth - ubi_btn.width - 20; ubi_btn.y = stage.stageHeight - ubi_btn.height - 20; addChild(ubi_btn); } private function verUbicacion(e:TouchEvent):void { if (ubi_activado) { ubi_activado = ubi.visible = false; ubi_btn.label = "Ubication"; } else { ubi_activado = true; ubi_btn.label = "Disable"; if (lat != 0) { ubi.visible = true; map.setCenter(new LatLng(lat, long), 14); ubi.setLatLng(new LatLng(lat, long)); } } } } }