How to instantiate a Point in golang-geo?

479 views
Skip to first unread message

fernand...@gmail.com

unread,
Sep 4, 2013, 3:26:10 PM9/4/13
to golan...@googlegroups.com
I'm trying to use the golang-geo library to do some calculations with geographical coordinates, but I can't seem to instantiate a point.

Everytime I try to do something like

    p := new(geo.Point)
    p.lat = 14.046237
    fmt.Println(p.lat)

I get an error stating that I cannot access the unexported fields.

Anything from the README of the project has proven to be unfruitful. Any hints on how should I do this?

Bruno Albuquerque

unread,
Sep 4, 2013, 5:04:55 PM9/4/13
to fernand...@gmail.com, golang-nuts
That library only seems to allow you to generate a point out of an address. In other words, you use a Geocoder implementation to get a Point.

In Go, fields that start with a lowercase letter are private. Thatś why you are seeing the error you are seeing.



--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Carlos Castillo

unread,
Sep 4, 2013, 7:29:17 PM9/4/13
to golan...@googlegroups.com, fernand...@gmail.com, b...@bug-br.org.br
I believe the person creating the package didn't consider that either, as there are examples of how to create Points that manually set the (unexported) fields that are impossible to do in go from anywhere but in the golang-geo package itself. IE: the tests could succeed, but no-one else can build points that way.

Neither of the package's forks resolve this either.

The simplest solution if making your own fork would be to create a New function that generates a point with given lat, long values. That way no other code is affected by renaming fields.

Alternatively, you could create an issue on the golang-geo issue tracker to get the original author to fix it themselves (https://github.com/kellydunn/golang-geo/issues).

Fernando Irías Escher

unread,
Sep 5, 2013, 7:30:26 PM9/5/13
to Carlos Castillo, golan...@googlegroups.com, b...@bug-br.org.br
Thanks a lot guys. I ended up implementing my implementing a Point struct and making the functions I needed by myself.

I might fork the project though and add the proper support for people trying to use this library more easily.

Thanks a lot for confirming the problem I found.

- Fernando.

defaul...@gmail.com

unread,
Sep 16, 2013, 8:25:03 PM9/16/13
to golan...@googlegroups.com, Carlos Castillo, b...@bug-br.org.br, fernand...@gmail.com
Hello there, author of golang-geo here :D

Carlos is correct in that I had not considered this behavior before, and something should be available for simple Point translations that doesn't require the use of SQL or external geocoding services.

Fernando, I welcome any Pull Requests you may wish to contribute to the project!  I would love to get any feedback you may have on the desired features, and having discussion there might also welcome other users to give their input on similar functionality.

- Kelly.

defaul...@gmail.com

unread,
Sep 16, 2013, 10:46:34 PM9/16/13
to golan...@googlegroups.com, Carlos Castillo, b...@bug-br.org.br, fernand...@gmail.com, defaul...@gmail.com
A quick update!  I've opened an issue and attached an outstanding change-set on a separate branch for this particular issue: https://github.com/kellydunn/golang-geo/issues/2.

Kelly Dunn

unread,
Sep 16, 2013, 11:45:42 PM9/16/13
to golan...@googlegroups.com, Carlos Castillo, b...@bug-br.org.br, fernand...@gmail.com, defaul...@gmail.com
Yet another update!

A pull request was opened to address the issue mentioned in this thread: https://github.com/kellydunn/golang-geo/pull/3
During its discussion, we decided to merge the changset in the issue I linked earlier.

Fernando, feel free to let me know if you have any outstanding issues.  It seems like your issue has been addressed, but if you continue to run into any problems feel free to open up an issue on github :)

- Kelly.
Reply all
Reply to author
Forward
0 new messages