V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
jss

请问 gorm 如何实现 根据经纬度换算距离 并排序

  •  
  •   jss · Jul 5, 2019 via iPhone · 3704 views
    This topic created in 2491 days ago, the information mentioned may be changed or developed.
    type MapInfo struct {
    ID int32 `json:"id" gorm:"primary_key"`
    Name string `json:"name" form:"name" validate:"required"`
    Longitude string `json:"longitude" form:"longitude" validate:"required"`
    Latitude string `json:"latitude" form:"latitude" validate:"required"`
    }
    7 replies    2019-07-08 17:04:45 +08:00
    congeec
        1
    congeec  
       Jul 5, 2019
    扔到 postgits 里,用 gist 索引,速度杠杠滴
    reus
        2
    reus  
       Jul 6, 2019
    用 PostGIS
    jss
        3
    jss  
    OP
       Jul 6, 2019
    @congeec 我用的是 mysql,请教一下 详细步骤
    jss
        4
    jss  
    OP
       Jul 6, 2019
    @reus 我用的是 mysql,请教一下 详细步骤
    beginor
        5
    beginor  
       Jul 6, 2019 via Android
    @jss 换数据库不值得,MySQL 也有空间扩展, 用空间类型+空间索引应该也是可以的。
    zjyl1994
        6
    zjyl1994  
       Jul 6, 2019
    写原生 sql 吧,你这种场景没有几个 orm 可以帮忙处理吧?
    TypeErrorNone
        7
    TypeErrorNone  
       Jul 8, 2019
    用 redis geo 类型存储
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2484 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 09:53 · PVG 17:53 · LAX 02:53 · JFK 05:53
    ♥ Do have faith in what you're doing.