flex+gmap
废话少说, 直接上代码:
onMapReady(event):void{
var latitude:Number = 36.07;
var longitude:Number = 103.75;
if(datacenter!=null && datacenters.length>0){
var tmpLatitude:Number = 0;
var tmpLongitude:Number = 0;
var length:int = 0;
for each(var datacenter:DataCenter in datacenters){
var coordinate:String = datacenter.coordinate;//新建数据中心时将地名对应的coordinate写入到数据库,此处是从数据库读出coordinate
if(coordinate!=null && coordinate!=""){
var latLng:Array = coordinae.split(/,/);
tmpLatitude+=Number(latLng[0]);
tmpLongitude+=Number(latLng[1]);
length++;
}
}
if(length!=0){//中心位置取多个数据中心的平均值
latitude = tmpLatitude/length;
longitude = tmpLogitude/length;
}
}
this.googMap.setCenter(new LatLng(latitude,longtitude),4, MapType.NORMAL_MAP_TYPE);
googleMap.addControl(new PositionControl(new PositionControlOptions()));
googleMap.addControl(new ZoomControl(new ZoomControlOptions()));
}
//标记
function initMapMarkers():void{
for each(var m:Marker in markers){
googleMap.removeOverlay(m);
}
markers.removeAll();
var arr:ArrayCollection = xxxx(后台返回的结果集)
for each (var entry:XXX in arr){
if(...业务判断){
var latLng:Array = coordinae.split(/,/);
latitude=Number(latLng[0]);
longtitude=Number(latLng[1]);
var colorValue=RGB...;
var markerOptions:MarkerOptions = new MarkerOptions({strokeStyle:xxx样式);
var marker:Marker = new Marker(new LatLng(latitude,longtitude),markerOptions);
marker.addEventListener(MapMouseEvent.click,showDatacenterInfo);
markers.addItem(marker);
googleMap.addOverlay(marker);
}
}
}
function showDatacenterInfo(event:MapMouseEvent):void{
//业务逻辑略掉
var content = 提示信息;
var infoWindow:InfoWindowOptions = new InfoWindowOptions(对象);
googleMap.openInfoWindow(event.latLng, infoWindow);
}