これはマッピング システムとして MapQuest を使用している人々にとって一般的な問題であるように思われるため、任意のリストまでの距離でカスタム POI をソートするソリューションを提供します。これはモバイル アプリケーション向けのソリューションであり、データグリッド上でリストを使用する理由です。
protected function sort_clickHandler():void
{
var dataSortField:SortField = new SortField();
dataSortField.numeric = true;
/* Create the Sort object and add the SortField object created earlier to the array of fields to sort on. */
var numericDataSort:Sort = new Sort();
numericDataSort.compareFunction=sortFunction;
/* Set the ArrayCollection object's sort property to our custom sort, and refresh the ArrayCollection. */
getAllMarkersResult.lastResult.sort = numericDataSort;
getAllMarkersResult.lastResult.refresh();
}
private function sortFunction(a:Object, b:Object, array:Array = null):int
{
var aPoi:LatLng = new LatLng(a.lat,a.lng);
var bPoi:LatLng = new LatLng(b.lat,b.lng);
var i:Number=GeodesicCalculatorUtil.calculateGeodesicDistance(FlexGlobals.topLevelApplication.currentLatLng2,aPoi,DistanceUnits.KILOMETERS);
var j:Number=GeodesicCalculatorUtil.calculateGeodesicDistance(FlexGlobals.topLevelApplication.currentLatLng2,bPoi,DistanceUnits.KILOMETERS);
return ObjectUtil.numericCompare(i, j);
}