V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
jss
V2EX  ›  Go 编程语言

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

  •  
  •   jss · 2019-07-05 21:46:18 +08:00 via iPhone · 3118 次点击
    这是一个创建于 1747 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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 条回复    2019-07-08 17:04:45 +08:00
    congeec
        1
    congeec  
       2019-07-05 22:06:46 +08:00
    扔到 postgits 里,用 gist 索引,速度杠杠滴
    reus
        2
    reus  
       2019-07-06 00:29:02 +08:00
    用 PostGIS
    jss
        3
    jss  
    OP
       2019-07-06 08:39:33 +08:00
    @congeec 我用的是 mysql,请教一下 详细步骤
    jss
        4
    jss  
    OP
       2019-07-06 08:46:34 +08:00
    @reus 我用的是 mysql,请教一下 详细步骤
    beginor
        5
    beginor  
       2019-07-06 22:02:04 +08:00 via Android
    @jss 换数据库不值得,MySQL 也有空间扩展, 用空间类型+空间索引应该也是可以的。
    zjyl1994
        6
    zjyl1994  
       2019-07-06 23:03:07 +08:00
    写原生 sql 吧,你这种场景没有几个 orm 可以帮忙处理吧?
    TypeErrorNone
        7
    TypeErrorNone  
       2019-07-08 17:04:45 +08:00
    用 redis geo 类型存储
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   958 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 21:22 · PVG 05:22 · LAX 14:22 · JFK 17:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.