- 修复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)
|
task.GetResult(0)
|
||||||
}
|
}
|
||||||
// if mapLimit {
|
// if mapLimit {
|
||||||
// retVal.TotalCount = len(retVal.Stores)
|
// retVal.TotalCount = len(retVal.Stores)f
|
||||||
// }
|
// }
|
||||||
} else {
|
} else {
|
||||||
// dao.Rollback(db)
|
// 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)
|
retVal.MapCenterLng, retVal.MapCenterLat = getMapCenter(retVal.Stores)
|
||||||
}
|
}
|
||||||
return retVal, err
|
return retVal, err
|
||||||
@@ -483,18 +484,16 @@ func getMapCenter(storeList []*StoreExt) (lng, lat float64) {
|
|||||||
lngAvg = lngAvg / storeListLenFloat
|
lngAvg = lngAvg / storeListLenFloat
|
||||||
latAvg = latAvg / storeListLenFloat
|
latAvg = latAvg / storeListLenFloat
|
||||||
|
|
||||||
lngMean := float64(0)
|
distAvg := float64(0)
|
||||||
latMean := float64(0)
|
|
||||||
for _, store := range storeList {
|
for _, store := range storeList {
|
||||||
lngMean += (store.FloatLng - lngAvg) * (store.FloatLng - lngAvg)
|
distAvg += math.Sqrt((store.FloatLng-lngAvg)*(store.FloatLng-lngAvg) + (store.FloatLat-latAvg)*(store.FloatLat-latAvg))
|
||||||
latMean += (store.FloatLat - latAvg) * (store.FloatLat - latAvg)
|
|
||||||
}
|
}
|
||||||
lngMean = math.Sqrt(lngMean / storeListLenFloat)
|
distAvg = (distAvg / storeListLenFloat)
|
||||||
latMean = math.Sqrt(latMean / storeListLenFloat)
|
maxDist := distAvg * 5
|
||||||
newStoreList := []*StoreExt{}
|
newStoreList := []*StoreExt{}
|
||||||
for _, store := range storeList {
|
for _, store := range storeList {
|
||||||
if store.FloatLng >= lngMean-lngAvg && store.FloatLng <= lngMean+lngAvg &&
|
dist := math.Sqrt((store.FloatLng-lngAvg)*(store.FloatLng-lngAvg) + (store.FloatLat-latAvg)*(store.FloatLat-latAvg))
|
||||||
store.FloatLat >= latMean-latAvg && store.FloatLat <= latMean+latAvg {
|
if dist < maxDist {
|
||||||
lng += store.FloatLng
|
lng += store.FloatLng
|
||||||
lat += store.FloatLat
|
lat += store.FloatLat
|
||||||
newStoreList = append(newStoreList, store)
|
newStoreList = append(newStoreList, store)
|
||||||
|
|||||||
Reference in New Issue
Block a user