kellydunn / golang-geo Goto Github PK
View Code? Open in Web Editor NEWGeographical calculations in Go.
License: MIT License
Geographical calculations in Go.
License: MIT License
As mentioned in the golang-nuts google group, users cannot currently specify latitude or longitude values while instantiating new Points.
I propose that something akin to NewPoint(lat float64, lng float64) (*Point)
should be implemented such that users may be able to create new Points while still keeping the internals private.
We could also implement some kind of getter for the internal fields of Points, like (p * Point) GetLat() (float64)
and (p* Point) GetLng() (float64)
such that users may be able to view the internals of these newly instantiated Points.
@FernandoEscher do you have any thoughts or outstanding pull requests you may want to make in regards to this issue?
There are problems with the travis build as in #46. Again there is a problem with goose:
$ go get -d bitbucket.org/liamstask/goose/lib/goose
package bitbucket.org/liamstask/goose/lib/goose: https://api.bitbucket.org/1.0/repositories/liamstask/goose: 410 Gone
The command "go get -d bitbucket.org/liamstask/goose/lib/goose" failed and exited with 1 during .
Your build has been stopped.
Somehow the link is gone on Bitbucket.
Until this is resolved all Travis builds will fail.
What about locale of geocode?
I am trying to use this library with Google App Engine which does not allow one to use the standard library to make HTTP requests. I ran into a similar issue with a Twitter API, but was able to replace the http.Client
since it was exposed in the API.
I believe a change like this could allow for a similar capability:
// This struct contains all the funcitonality
// of interacting with the Google Maps Geocoding Service
type GoogleGeocoder struct{
HttpClient *http.Client
}
...
// Issues a request to the google geocoding service and forwards the passed in params string
// as a URL-encoded entity. Returns an array of byes as a result, or an error if one occurs during the process.
func (g *GoogleGeocoder) Request(params string) ([]byte, error) {
if g.HttpClient == nil {
g.HttpClient = &http.Client{}
}
client := g.HttpClient
...
Thoughts?
The p.Contains(pt)
logic for polygons with holes may return bad results.
Context: I have not been able to find documentation for creating a polygon with holes. I assume that you simply continue to add call p.Add(pt)
for the points of the holes inside the polygon.
If my assumption is correct, then false line segments are created between the boundary and contained holes (or between successive holes). If a raycast intersects with an odd number of these false segments, the wrong result is returned.
If my assumption is incorrect, better documentation on how to create polygons with holes would be appreciated.
I don't have much experience with Go and I would appreciate a complete example which I can save and see if it works (that means I can see where I have to make changes).
See http://stackoverflow.com/q/28998709/562769 for my related question.
As confirmed by the owner of goose
, a go migration tool, the project is no longer be actively supported and may change hands of ownership soon. (Comment here)
This might be a contributing factor as to why go get bitbucket.org/liamstask/goose/cmd/goose
is no longer working as intended.
Until this is resolved, travis builds are failing:
Using worker: worker-linux-da6418d7-2.bb.travis-ci.org:travis-linux-1
system_info
Build system information
Build language: go
Build image provisioning date and time
Wed Feb 4 18:22:50 UTC 2015
Operating System Details
Distributor ID: Ubuntu
Description: Ubuntu 12.04 LTS
Release: 12.04
Codename: precise
Linux Version
2.6.32-042stab090.5
Cookbooks Version
23bb455 https://github.com/travis-ci/travis-cookbooks/tree/23bb455
GCC version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
LLVM version
clang version 3.4 (tags/RELEASE_34/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
Pre-installed Ruby versions
ruby-1.9.3-p551
Pre-installed Node.js versions
v0.10.36
Pre-installed Go versions
1.4.1
Redis version
redis-server 2.8.19
riak version
2.0.2
MongoDB version
MongoDB 2.4.12
CouchDB version
couchdb 1.6.1
Neo4j version
1.9.4
Cassandra version
2.0.9
RabbitMQ Version
3.4.3
ElasticSearch version
1.4.0
Installed Sphinx versions
2.0.10
2.1.9
2.2.6
Default Sphinx version
2.2.6
Installed Firefox version
firefox 31.0esr
PhantomJS version
1.9.8
ant -version
Apache Ant(TM) version 1.8.2 compiled on December 3 2011
mvn -version
Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T17:29:23+00:00)
Maven home: /usr/local/maven
Java version: 1.7.0_76, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-oracle/jre
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "2.6.32-042stab090.5", arch: "amd64", family: "unix"
git.checkout
0.47s$ git clone --depth=50 --branch=v1.0.0-work-in-progress https://github.com/kellydunn/golang-geo.git kellydunn/golang-geo
Cloning into 'kellydunn/golang-geo'...
remote: Counting objects: 622, done.
remote: Compressing objects: 100% (305/305), done.
remote: Total 622 (delta 309), reused 595 (delta 288), pack-reused 0
Receiving objects: 100% (622/622), 179.90 KiB | 0 bytes/s, done.
Resolving deltas: 100% (309/309), done.
Checking connectivity... done.
$ cd kellydunn/golang-geo
$ git checkout -qf 9b75a0c43d4f209ac8a7c62331e4868acdc045a5
Installing gimme from https://raw.githubusercontent.com/meatballhat/gimme/v0.2.3/gimme
Setting environment variables from .travis.yml
$ export DB=postgres
$ export GO_ENV=test
4.28s$ eval "$(gimme 1.2.1)"
go version go1.2.1 linux/amd64
$ export GOPATH=$HOME/gopath
$ export PATH=$HOME/gopath/bin:$PATH
$ mkdir -p $HOME/gopath/src/github.com/kellydunn/golang-geo
$ rsync -az ${TRAVIS_BUILD_DIR}/ $HOME/gopath/src/github.com/kellydunn/golang-geo/
$ export TRAVIS_BUILD_DIR=$HOME/gopath/src/github.com/kellydunn/golang-geo
$ cd $HOME/gopath/src/github.com/kellydunn/golang-geo
$ gimme version
v0.2.3
$ go version
go version go1.2.1 linux/amd64
go.env
$ go env
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/travis/gopath"
GORACE=""
GOROOT="/home/travis/.gimme/versions/go1.2.1.linux.amd64"
GOTOOLDIR="/home/travis/.gimme/versions/go1.2.1.linux.amd64/pkg/tool/linux_amd64"
TERM="dumb"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CXX="g++"
CGO_ENABLED="1"
before_install
0.01s$ export PATH=/home/travis/gopath/bin:$PATH
4.29s$ go get bitbucket.org/liamstask/goose/cmd/goose
# github.com/mattn/go-sqlite3
Go type not supported in export: [0]byte
Go type not supported in export: [0]byte
Go type not supported in export: [0]byte
Go type not supported in export: [0]byte
Go type not supported in export: [0]byte
Go type not supported in export: [0]byte
Go type not supported in export: [0]byte
Go type not supported in export: [0]byte
Go type not supported in export: [0]byte
Go type not supported in export: [0]byte
The command "go get bitbucket.org/liamstask/goose/cmd/goose" failed and exited with 2 during .
Your build has been stopped.
Acceptance criteria:
Much like the style of the google geocoder, each geocoder implementation should use a data transfer object style struct to marshal and unmarshal responses from various APIs; this could open up new posibilities for the geocoders and make it less hacky to parse responses from various apis.
vendor/github.com/kellydunn/golang-geo/sql_conf.go:79: unreachable code exit status 1
When you try to reverse-geocode lat=0, lng=0 it throws an error as no address is nearby.
Hello,
Not sure if its an issue or if its my shoddy attempt at using the API, but I don't see support for adding an API key to the end of the urls here. Is that something you are interested in supporting? I could add if so.
I added some tests for it in #69. It seems that the IsClosed()
method always returns true.
// point = &{43.9038438 2.1429772}
for {
point2, err := gc.ReverseGeocode(point)
if err != nil {
fmt.Println("erro 2")
}
we never receive an error but go right into a panic
Got a strange error
$ go get github.com/kellydunn/golang-geo
# github.com/kellydunn/golang-geo
/usr/local/go/src/pkg/github.com/kellydunn/golang-geo/sql_conf.go:27: function ends without a return statement
Hi Kelly,
I notice that the test coverage for the *Geocoder
is a bit low. Will you be interested in a PR where I refactor the Geocode()
and ReverseGeocode()
methods to mock out the API calls.
For example, in GoogleGeocoder
, I update the struct to have a field function:
type GoogleGeocoder struct {
sendRequest func(params string) ([]byte, error)
}
Then I changed the Geocode()
method to call g.sendRequest()
like this:
func (g *GoogleGeocoder) Geocode(address string) (*Point, error) {
if g.sendRequest == nil { // this can go into the struct constructor
g.sendRequest = g.Request
}
data, err := g.sendRequest(queryStr)
if err != nil {
return nil, err
}
This will makes it easier to test these methods. For example, I can mock the sendRequest
field in the test like this:
func TestGeocode(t *testing.T) {
address := "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA"
g := GoogleGeocoder{
sendRequest: func(params string) ([]byte, error) {
return []byte(`{
"results":[
{"formatted_address":"1600 Amphitheatre Parkway, Mountain View, CA 94043, USA",
"geometry":{"location":{
"lat":37.4224764,
"lng":-122.0842499}
}
}
],
"status":"OK"
}`), nil
},
}
actual, err := g.Geocode(address)
if err != nil {
t.Error("Unexpected error: ", err)
}
expected := &Point{lat: 37.4224764, lng: -122.0842499}
if !assertPointsEqual(actual, expected, 4) {
t.Errorf("Expected point to be %+v, but got %+v", expected, actual)
}
}
Obviously, this can be done for all the different types of Geocoder
s. With this change, existing tests continue to pass, with test coverage for the Geocoder
s increased from around 30% to 78%.
WDYT?
Hello
I am in the need of an golang api for https://developers.google.com/maps/documentation/geolocation/intro
So i am wondering, would it be fitting for this project if i produced a PR, or should i keep it separate?
could you advise me if this library can so his.
I dont need to use the SQL functionality for now. i just need to do it all in memory in the middle tier.
i have every users gps location.
I have a event, for which i have the GPS location.
So i need to write a job that searches for any users location, within 20 km of the Event location.
The advantage of this is that i can do all this without having to use google maps APi and all that
This issue is to test a trello integration
File Polygon.go - func Contains
What will happen if point.lat and start.lat are equal? Be careful in this case.
user@FRODO /d/goworkspace/bin
$ go get github.com/kellydunn/golang-geo
# cd D:\goworkspace\src\github.com\kylelemons\go-gypsy; git pull --ff-only
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
package github.com/kylelemons/go-gypsy/yaml: exit status 1
When doing a query in mongodb about the distance between those 2 points the result is a rounded 1079km.
However the result of the great circle distance function of this package is 1118.298549 , km I assume.
With manual testing I found the factor 0.965 to achieve nearly mongodb results.
How can it be that those 2 methods result in different results?
package main
import (
"fmt"
geo "github.com/kellydunn/golang-geo"
)
func main() {
p1 := geo.NewPoint(9.1829321, 48.7758459)
p2 := geo.NewPoint(5.03131, 39.542448)
dist := p1.GreatCircleDistance(p2)
fmt.Printf("great circle distance: %f\n", dist)
fmt.Printf("mongo ~ distance: %f\n", dist*0.965)
}
my mongodb query is, using the official driver
geoStage := bson.D{{
"$geoNear", bson.D{
{"near", profile.Location}, // see below
{"distanceField", "distance"},
{"minDistance", 1},
{"maxDistance", radius},
{"spherical", true},
},
},
}
// -- below
// Location is a GeoJSON type.
type Location struct {
Type string `json:"type" bson:"type"`
Coordinates []float64 `json:"coordinates" bson:"coordinates"`
}
Sorry if this is a silly question. On the following line:
https://github.com/kellydunn/golang-geo/blob/develop/google_geocoder.go#L122
You are getting a pointer value to the address of the struct, so a pointer to a pointer. Is it necessary to have this for proper unmarhsalling or would a single pointer suffice?
The units of the return values should be documented.
Some points on boundary line or on polygon vertices return false in contains- Polygon.
For example ,
polygon- (0,0), (5, 0), (5, 5 ) , (0, 5) returns false for point (0,0)
Hi, thx for great lib.
You have panic in https://github.com/kellydunn/golang-geo/blob/master/sql_mapper.go#L33. It's mistake ?
Allow users to run tests in a database agnostic way
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.