- 修复getMapCenter的bug
This commit is contained in:
@@ -428,12 +428,13 @@ func GetStores(ctx *jxcontext.Context, keyword string, params map[string]interfa
|
||||
task.GetResult(0)
|
||||
}
|
||||
// if mapLimit {
|
||||
// retVal.TotalCount = len(retVal.Stores)
|
||||
// retVal.TotalCount = len(retVal.Stores)f
|
||||
// }
|
||||
} else {
|
||||
// dao.Rollback(db)
|
||||
}
|
||||
if mapLimit && len(retVal.Stores) > 0 {
|
||||
retVal.Stores = append(retVal.Stores, &StoreExt{})
|
||||
if len(retVal.Stores) > 0 {
|
||||
retVal.MapCenterLng, retVal.MapCenterLat = getMapCenter(retVal.Stores)
|
||||
}
|
||||
return retVal, err
|
||||
@@ -483,18 +484,16 @@ func getMapCenter(storeList []*StoreExt) (lng, lat float64) {
|
||||
lngAvg = lngAvg / storeListLenFloat
|
||||
latAvg = latAvg / storeListLenFloat
|
||||
|
||||
lngMean := float64(0)
|
||||
latMean := float64(0)
|
||||
distAvg := float64(0)
|
||||
for _, store := range storeList {
|
||||
lngMean += (store.FloatLng - lngAvg) * (store.FloatLng - lngAvg)
|
||||
latMean += (store.FloatLat - latAvg) * (store.FloatLat - latAvg)
|
||||
distAvg += math.Sqrt((store.FloatLng-lngAvg)*(store.FloatLng-lngAvg) + (store.FloatLat-latAvg)*(store.FloatLat-latAvg))
|
||||
}
|
||||
lngMean = math.Sqrt(lngMean / storeListLenFloat)
|
||||
latMean = math.Sqrt(latMean / storeListLenFloat)
|
||||
distAvg = (distAvg / storeListLenFloat)
|
||||
maxDist := distAvg * 5
|
||||
newStoreList := []*StoreExt{}
|
||||
for _, store := range storeList {
|
||||
if store.FloatLng >= lngMean-lngAvg && store.FloatLng <= lngMean+lngAvg &&
|
||||
store.FloatLat >= latMean-latAvg && store.FloatLat <= latMean+latAvg {
|
||||
dist := math.Sqrt((store.FloatLng-lngAvg)*(store.FloatLng-lngAvg) + (store.FloatLat-latAvg)*(store.FloatLat-latAvg))
|
||||
if dist < maxDist {
|
||||
lng += store.FloatLng
|
||||
lat += store.FloatLat
|
||||
newStoreList = append(newStoreList, store)
|
||||
|
||||
Reference in New Issue
Block a user