当我使用google的javascript API创建应用程序时遇到了同样的问题,解决方法是在回调函数上创建多个标记的闭包。
我似乎无法找到制作多个自定义标记的示例,除了使用一些随机数学函数创建多个标记之外的任何其他内容。
GlobalVars是一个包含静态公共var类型的类,可以跟上多个地址,lats,lng等...
我尝试过使用markermanager,但它有一些我最终放弃的问题。
从
开始 retrieveLatLngAddress.addEventListener(GeocodingEvent.GEOCODING_SUCCESS, function(event:GeocodingEvent):void{
这是我开始按地址进行地理编码的地方,而不是像以前那样使用httpservice,但是我遇到了一个httpservice结果的问题会比另一个更快地返回,这反过来会把错误的数据放错标记
显然,我还没有找到解决方案,因为这种做法也是如此。
问题是,如何检索多个标记信息并按顺序保留所有标记选项并返回信息。
以下是代码:
public function makeMultipleMarkers(destinationAllObj:Object):void {
removeRouteMarkers();
myMarkers = [];
GlobalVars.myIcon = [];
GlobalVars.someAddress = [];
GlobalVars.sName = [];
markerMgr.clearMarkers();
GlobalVars.destinationInc = 0;
retrieveLatLngAddress = new ClientGeocoder();
retrieveLatLngAddress.addEventListener(GeocodingEvent.GEOCODING_SUCCESS, function(event:GeocodingEvent):void{
var result:Placemark = GeocodingResponse(event.response).placemarks[0];
var latLngStr:String = result.point.toString();
GlobalVars.panoLatLng = latLngStr.split(',');
var deleteLeftParen:String = GlobalVars.panoLatLng[0];
GlobalVars.panoLatLng[0] = deleteLeftParen.replace("(","");
var deleteRightParen:String = GlobalVars.panoLatLng[1];
GlobalVars.panoLatLng[1] = deleteRightParen.replace(")","");
bounds = new LatLngBounds();
var request:URLRequest = new URLRequest(GlobalVars.myIcon[GlobalVars.destinationInc]);
var imageLoader:Loader = new Loader();
imageLoader.load(request);
imageLoader.name = String(GlobalVars.myIcon[GlobalVars.destinationInc]);
// Alert.show(GlobalVars.panoLatLng[0]);
var tmpLatLng:LatLng = new LatLng(GlobalVars.panoLatLng[0], GlobalVars.panoLatLng[1]);
someMarker = new Marker(tmpLatLng, new MarkerOptions({
icon: imageLoader,
tooltip: destinationAllObj[GlobalVars.destinationInc].SNAME+', '+GlobalVars.someAddress[GlobalVars.destinationInc],
hasShadow: false
}));
someMarker.addEventListener(MapMouseEvent.CLICK, function(event:MapMouseEvent):void{
var marker:Marker = event.target as Marker;
var markerContent:String = marker.getOptions().tooltip.toString();
textInput.text = marker.getOptions().tooltip.toString();
marker.openInfoWindow(new InfoWindowOptions({content: markerContent}));
sendSomeLatLngToSv(event.latLng);
var lastIndexOfDashStr:String = marker.getOptions().icon.name;
GlobalVars.iconObj = lastIndexOfDashStr;
var tmpArr:Array = new Array;
var tmpStr:String = event.currentTarget.getOptions().tooltip;
tmpArr = tmpStr.split(',');
GlobalVars.panoAddr[0] = tmpArr[1];
GlobalVars.sName[0] = tmpArr[0];
});
myMarkers.push(someMarker);
googleMap.addOverlay(someMarker);
for each(someMarker in myMarkers)
{
var newLatLng:LatLng = someMarker.getLatLng();
bounds.extend(newLatLng);
}
GlobalVars.destinationInc++;
if(GlobalVars.newDestObj.length == GlobalVars.destinationInc)
{
statusTxt.text = "Complete";
googleMap.setCenter(bounds.getCenter(), (googleMap.getBoundsZoomLevel(bounds))-2, MapType.HYBRID_MAP_TYPE);
// markerMgr.addMarkers(myMarkers, 8, 16);
// markerMgr.refresh();
}
});
retrieveLatLngAddress.addEventListener(GeocodingEvent.GEOCODING_FAILURE, geocoderMarkersFailure);
for(GlobalVars.destinationCounter = 0; GlobalVars.destinationCounter < destinationAllObj.length; GlobalVars.destinationCounter++)
{
// Alert.show(destinationAllObj[GlobalVars.destinationCounter].ICON);
GlobalVars.someAddress[GlobalVars.destinationCounter] = destinationAllObj[GlobalVars.destinationCounter].SLOC;
GlobalVars.sName[GlobalVars.destinationCounter] = destinationAllObj[GlobalVars.destinationCounter].SNAME;
if(destinationAllObj[GlobalVars.destinationCounter].ICON == "")
{
GlobalVars.myIcon[GlobalVars.destinationCounter] = "images/school_32.png";
// Alert.show(GlobalVars.destinationCounter+" "+GlobalVars.myIcon[GlobalVars.destinationCounter]);
}
else
{
GlobalVars.myIcon[GlobalVars.destinationCounter] = destinationAllObj[GlobalVars.destinationCounter].ICON;
}
statusTxt.text = "Processing data, please wait...";
}
for(GlobalVars.destinationCounter = 0; GlobalVars.destinationCounter < destinationAllObj.length; GlobalVars.destinationCounter++)
{
var tempURL:String = "http://kronusproductions.com/mycarpaysme_ajax/php/google_lat_lng_flex_lausd.php?addr="+destinationAllObj[GlobalVars.destinationCounter].SLOC;
// loadMyXml(tempURL);
retrieveLatLngAddress.geocode(destinationAllObj[GlobalVars.destinationCounter].SLOC);
statusTxt.text = "Processing data, please wait...";
}
}
答案 0 :(得分:0)
好的,我做了三件事让这个工作正常。
首先,我只写了一个for循环。
其次,我在三秒钟后第二次调用makeMultipleMarkers函数。
第三,如果我仍然收到500的状态代码,那么我会向谷歌发送请求,直到我收到状态代码为500.
public function makeMultipleMarkers(destinationAllObj:Object):void {
myMarkers = [];
GlobalVars.myIcon = [];
GlobalVars.someAddress = [];
GlobalVars.sName = [];
GlobalVars.destinationInc = 0;
googleMap.getPaneManager().clearOverlays();
bounds = new LatLngBounds();
retrieveLatLngAddress = new ClientGeocoder();
retrieveLatLngAddress.addEventListener(GeocodingEvent.GEOCODING_SUCCESS, function(event:GeocodingEvent):void{
var result:Placemark = GeocodingResponse(event.response).placemarks[0];
var latLngStr:String = result.point.toString();
// GlobalVars.statusCode = event.status;
var request:URLRequest;
var imageLoader:Loader = new Loader();
if(GlobalVars.destinationInc < destinationAllObj.length)
{
imageLoader.load((destinationAllObj[GlobalVars.destinationInc].ICON == "")? request = new URLRequest("images/school_32.png") : request = new URLRequest(destinationAllObj[GlobalVars.destinationInc].ICON));
imageLoader.name = String(destinationAllObj[GlobalVars.destinationInc].ICON);
someMarker = new Marker(result.point, new MarkerOptions({
icon: imageLoader,
tooltip: destinationAllObj[GlobalVars.destinationInc].SNAME+', '+destinationAllObj[GlobalVars.destinationInc].SLOC,
hasShadow: false
}));
someMarker.addEventListener(MapMouseEvent.CLICK, function(event:MapMouseEvent):void{
directionsSteps.removeAll();
var marker:Marker = event.target as Marker;
var markerContent:String = marker.getOptions().tooltip.toString();
var firstComma:Number = markerContent.indexOf(",");
textInput.text = markerContent.substr((firstComma+2),markerContent.length);
var tempInfoWinOpts:InfoWindowOptions = new InfoWindowOptions({
content: markerContent,
width: 450
});
marker.openInfoWindow(tempInfoWinOpts);
sendSomeLatLngToSv(event.latLng);
var lastIndexOfDashStr:String = marker.getOptions().icon.name;
GlobalVars.iconObj = lastIndexOfDashStr;
var tmpArr:Array = new Array;
var tmpStr:String = event.currentTarget.getOptions().tooltip;
tmpArr = tmpStr.split(',');
GlobalVars.panoAddr[0] = tmpArr[1];
GlobalVars.sName[0] = tmpArr[0];
});
googleMap.addOverlay(someMarker);
myMarkers.push(someMarker);
GlobalVars.destinationInc++;
}
for each(someMarker in myMarkers)
{
var newLatLng:LatLng = someMarker.getLatLng();
bounds.extend(newLatLng);
}
if(destinationAllObj.length == GlobalVars.destinationInc)
{
statusTxt.text = "Complete";
var tempNum:Number = googleMap.getBoundsZoomLevel(bounds);
googleMap.setCenter(bounds.getCenter(), (tempNum), MapType.HYBRID_MAP_TYPE);
}
});
retrieveLatLngAddress.addEventListener(GeocodingEvent.GEOCODING_FAILURE, geocoderMarkersFailure);
for(GlobalVars.destinationCounter = 0; GlobalVars.destinationCounter < destinationAllObj.length; GlobalVars.destinationCounter++)
{
statusTxt.text = "Processing data, please wait...";
retrieveLatLngAddress.geocode(destinationAllObj[GlobalVars.destinationCounter].SLOC);
}
}
在区域数据网格中单击某个项目后,等待3秒钟再次调用该函数。功能类似于刷新数据网格。
public function selectedItemChanged(event:ListEvent):void
{
this.parentDocument.flexGoogleMap.directionsSteps.removeAll();
tempId = event.currentTarget.selectedItem.district_id;
this.parentDocument.passIdToRemoteGetSchoolsLocations(tempId);
setTimeout(mTimeOut, 3000);
}
public function mTimeOut():void{
this.parentDocument.passIdToRemoteGetSchoolsLocations(tempId)
}
如果返回状态代码500。
public function geocoderMarkersFailure(event:GeocodingEvent):void
{
var result:Number = event.status;
statusTxt.text = "Error: "+result+" processing address, re-processing, please wait 10-25 seconds...";
GlobalVars.statusCode = result;
if(GlobalVars.statusCode == 500)
{
setTimeout(statusFiveHundred, 10000);
GlobalVars.statusCode = 0;
}
}
public function statusFiveHundred():void{
this.parentDocument.passAllDestinations();
}
this.parentDocument.passAllDestinations()调用makeMultipleMarkers等。
以下是该应用的网址 - 仍处于测试阶段: enter link description here
顺便说一下,这个应用程序是为了让我的老板不必开车到洛杉矶的每所学校。通过这种方式,他可以点击特定的学区,然后在主干道(高速公路,三车道或两车道)旁边选择一所学校,确定学校是否可以在该特定地点附近放置广告,然后是他的销售推销到那边的学校。另一个BTW,为什么bin-release文件夹中的.swf文件不起作用,而bin-debug中的.swf呢?