Skip to content

geopoint is a go package to handle PostGIS point type.

License

Notifications You must be signed in to change notification settings

suifengtec/geopoint

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

geopoint

wercker status

geopoint is a go package to handle PostGIS point type.

Init

if you do not use go module function , you need to get it via the following command:

go get github.com/suifengtec/geopoint

import it in your go package or go project:

import(

    "github.com/suifengtec/geopoint"
)

Use it

p1 := geopoint.GeoPoint{Lng: 113.538639, Lat: 34.826563}
//to String via String() or p1.ToString()
p1.String()
//to JSON string
p1.JSONString()
//Scan PostGIS point data in db to Geopiont type.
var p2 geopoint.GeoPoint
user := GetOneRowFromDB(2)
p2.Scan(user.Geog)
fmt.Println(p2.String())


//Query Geopoint relatived instances by distance range helper example:

//GetUsersInDistanceRange ...
func GetUsersInDistanceRange(p geopoint.GeoPoint, d int64) []User {

    list := make([]User, 0)
    // query helper.
    qStr := p.GetPointsQueryStringWithIn(d)
    //X is the xorm.Engine pointer.
    err := X.Where(qStr).Desc("id").Find(&list)
    if err != nil {
        log.Fatal(err)
    }
    return list
}

Learn more

doc on godoc.org

About

geopoint is a go package to handle PostGIS point type.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages