문제

I'm making an app in AS3. I'm displaying Google map and I'd like to add Child (texts, shapes) at coordinates points. So if you move the map, the childs will stay at their coordinates points.

Here's my code for now :

How can I add a child at an exact coordinates point ?

Like :

var myChild:MovieClip;
myChild= new drawShape; 
addChild(myChild);
myChild(-22.2758000, 166.4580000);

(But the code is wrong. Do you know how I can do it ?)

Thx !

my code :

import com.google.maps.LatLng;
import com.google.maps.Map;
import com.google.maps.MapEvent;
import com.google.maps.MapType;
import com.google.maps.MapMouseEvent;
import com.google.maps.overlays.Marker;
import com.google.maps.LatLng;
import flash.geom.Rectangle;
import com.google.maps.MapMouseEvent;
import com.google.maps.overlays.Polyline;
import com.google.maps.overlays.PolylineOptions;
import com.google.maps.styles.StrokeStyle;
import com.google.maps.controls.NavigationControl; 
import com.google.maps.controls.MapTypeControl; 
import com.google.maps.controls.OverviewMapControl; 

var my_map:Map = new Map();
my_map.key = "AIzaSyCxiPVh482UPJ-cM6uBg5Fd88mTjxmQNV0"; 
my_map.sensor = "true";
addChild(my_map);
my_map.setSize(new Point(1203, 800));
my_map.addEventListener(MapEvent.MAP_READY, onMapReady);


function onMapReady(event:Event):void {
my_map.setCenter(new LatLng(-22.2758000,166.4580000), 15, MapType.NORMAL_MAP_TYPE);

var my_marker1:Marker = new Marker(new LatLng(-22.2758000,166.4580000));
my_map.addOverlay(my_marker1); 

my_map.addControl(new MapTypeControl());
my_map.addControl(new OverviewMapControl());
my_map.addControl(new NavigationControl());



var polyline:Polyline = new Polyline([
new LatLng(-22.2758000, 166.4580000),
new LatLng(-22.2760383, 166.4687288),
new LatLng(-22.2683338, 166.4687288),
new LatLng(-22.2675395, 166.4572275),
new LatLng(-22.2758000, 166.4580000)], 

new PolylineOptions({strokeStyle: new StrokeStyle({
 color: 0xFF0000,
thickness: 4,
alpha: 0.7}) }));
            polyline.addEventListener(MapMouseEvent.CLICK, polylineClickHandler);
            my_map.addOverlay(polyline);



        }

function polylineClickHandler(event:MapMouseEvent):void{
            trace("polyline clicked.");
        }
도움이 되었습니까?

해결책

Yes and No. You can't simply add objects that you want on the map. But you can imitate adding custom objects by the help of Markers. Markers have icon property:

var markerOptions:MarkerOptions = new MarkerOptions();
markerOptions.icon = new PersonalShape();
markerOptions.iconAlignment = MarkerOptions.ALIGN_VERTICAL_CENTER;

var marker:Marker = new Marker(new LatLng(-22.2758000,166.4580000), markerOptions);
map.addOverlay(marker);

And I have sad news for you:

The API will continue to work until September 2, 2014. After that date, the API will no longer be available

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top