-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
12,856 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/twiglab/crm/adv/latlng" | ||
) | ||
|
||
func main() { | ||
l := latlng.ToIndex(37.775938728915946, -122.41795063018799) | ||
fmt.Println(l) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module github.com/twiglab/crm/adv | ||
|
||
go 1.23.1 | ||
|
||
require ( | ||
entgo.io/ent v0.14.1 | ||
github.com/google/uuid v1.6.0 | ||
github.com/jackc/pgx/v5 v5.7.1 | ||
github.com/uber/h3-go/v4 v4.1.2 | ||
) | ||
|
||
require ( | ||
ariga.io/atlas v0.19.1-0.20240203083654-5948b60a8e43 // indirect | ||
github.com/agext/levenshtein v1.2.1 // indirect | ||
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect | ||
github.com/go-openapi/inflect v0.19.0 // indirect | ||
github.com/google/go-cmp v0.6.0 // indirect | ||
github.com/hashicorp/hcl/v2 v2.13.0 // indirect | ||
github.com/jackc/pgpassfile v1.0.0 // indirect | ||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect | ||
github.com/jackc/puddle/v2 v2.2.2 // indirect | ||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect | ||
github.com/rogpeppe/go-internal v1.13.1 // indirect | ||
github.com/stretchr/testify v1.9.0 // indirect | ||
github.com/yuin/gopher-lua v1.1.1 // indirect | ||
github.com/zclconf/go-cty v1.8.0 // indirect | ||
golang.org/x/crypto v0.27.0 // indirect | ||
golang.org/x/mod v0.20.0 // indirect | ||
golang.org/x/sync v0.8.0 // indirect | ||
golang.org/x/text v0.18.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
ariga.io/atlas v0.19.1-0.20240203083654-5948b60a8e43 h1:GwdJbXydHCYPedeeLt4x/lrlIISQ4JTH1mRWuE5ZZ14= | ||
ariga.io/atlas v0.19.1-0.20240203083654-5948b60a8e43/go.mod h1:uj3pm+hUTVN/X5yfdBexHlZv+1Xu5u5ZbZx7+CDavNU= | ||
entgo.io/ent v0.14.1 h1:fUERL506Pqr92EPHJqr8EYxbPioflJo6PudkrEA8a/s= | ||
entgo.io/ent v0.14.1/go.mod h1:MH6XLG0KXpkcDQhKiHfANZSzR55TJyPL5IGNpI8wpco= | ||
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= | ||
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= | ||
github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8= | ||
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= | ||
github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw= | ||
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/go-openapi/inflect v0.19.0 h1:9jCH9scKIbHeV9m12SmPilScz6krDxKRasNNSNPXu/4= | ||
github.com/go-openapi/inflect v0.19.0/go.mod h1:lHpZVlpIQqLyKwJ4N+YSc9hchQy/i12fJykb83CRBH4= | ||
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= | ||
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= | ||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= | ||
github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= | ||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= | ||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= | ||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= | ||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= | ||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||
github.com/hashicorp/hcl/v2 v2.13.0 h1:0Apadu1w6M11dyGFxWnmhhcMjkbAiKCv7G1r/2QgCNc= | ||
github.com/hashicorp/hcl/v2 v2.13.0/go.mod h1:e4z5nxYlWNPdDSNYX+ph14EvWYMFm3eP0zIUqPc2jr0= | ||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= | ||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= | ||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= | ||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= | ||
github.com/jackc/pgx/v5 v5.7.1 h1:x7SYsPBYDkHDksogeSmZZ5xzThcTgRz++I5E+ePFUcs= | ||
github.com/jackc/pgx/v5 v5.7.1/go.mod h1:e7O26IywZZ+naJtWWos6i6fvWK+29etgITqrqHLfoZA= | ||
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo= | ||
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= | ||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= | ||
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= | ||
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= | ||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= | ||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= | ||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= | ||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= | ||
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= | ||
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= | ||
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y= | ||
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= | ||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM= | ||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII= | ||
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o= | ||
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= | ||
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= | ||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= | ||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= | ||
github.com/uber/h3-go/v4 v4.1.2 h1:QHGEcldBZArx51UyTkQprFMUXaIlEkLV88zWUt8u2LY= | ||
github.com/uber/h3-go/v4 v4.1.2/go.mod h1:VDpXVn4NLetBoISLEbiTVNstwW00bhHolV8I+jx9G+4= | ||
github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4= | ||
github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= | ||
github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M= | ||
github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw= | ||
github.com/zclconf/go-cty v1.8.0 h1:s4AvqaeQzJIu3ndv4gVIhplVD0krU+bgrcLSVUnaWuA= | ||
github.com/zclconf/go-cty v1.8.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= | ||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A= | ||
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70= | ||
golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0= | ||
golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= | ||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= | ||
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= | ||
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= | ||
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= | ||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= | ||
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= | ||
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= | ||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package latlng | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/uber/h3-go/v4" | ||
) | ||
|
||
type Index struct { | ||
Index6 string | ||
Index7 string | ||
Index8 string | ||
|
||
Lat, Lng float64 | ||
} | ||
|
||
func ToIndex(lat, lng float64) Index { | ||
latLng := h3.NewLatLng(lat, lng) | ||
|
||
index6 := fmt.Sprint(latLng.Cell(6)) | ||
index7 := fmt.Sprint(latLng.Cell(7)) | ||
index8 := fmt.Sprint(latLng.Cell(8)) | ||
|
||
return Index{ | ||
Index6: index6, | ||
Index7: index7, | ||
Index8: index8, | ||
|
||
Lat: lat, | ||
Lng: lng, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
package loc | ||
|
||
/* | ||
百度地图API 百度坐标 | ||
腾讯搜搜地图API 火星坐标 | ||
搜狐搜狗地图API 搜狗坐标 | ||
阿里云地图API 火星坐标 | ||
图吧MapBar地图API 图吧坐标 | ||
高德MapABC地图API 火星坐标 | ||
灵图51ditu地图API 火星坐标 | ||
*/ | ||
|
||
import ( | ||
"math" | ||
) | ||
|
||
// GPSUtil is a utility class for GPS calculations. | ||
// 小写方法是私有方法,大写方法是公有方法 可根据需要调整 | ||
type GPSUtil struct { | ||
} | ||
|
||
const ( | ||
pi = math.Pi // 3.1415926535897932384626 // 圆周率 | ||
x_pi = math.Pi * 3000.0 / 180.0 // 圆周率对应的经纬度偏移 | ||
a = 6378245.0 // 长半轴 | ||
ee = 0.00669342162296594323 // 扁率 | ||
) | ||
|
||
func transformLat(x, y float64) float64 { | ||
ret := -100.0 + 2.0*x + 3.0*y + 0.2*y*y + 0.1*x*y + 0.2*math.Sqrt(math.Abs(x)) | ||
ret += (20.0*math.Sin(6.0*x*pi) + 20.0*math.Sin(2.0*x*pi)) * 2.0 / 3.0 | ||
ret += (20.0*math.Sin(y*pi) + 40.0*math.Sin(y/3.0*pi)) * 2.0 / 3.0 | ||
ret += (160.0*math.Sin(y/12.0*pi) + 320*math.Sin(y*pi/30.0)) * 2.0 / 3.0 | ||
return ret | ||
} | ||
|
||
func (receiver *GPSUtil) transformLat(x, y float64) float64 { | ||
ret := -100.0 + 2.0*x + 3.0*y + 0.2*y*y + 0.1*x*y + 0.2*math.Sqrt(math.Abs(x)) | ||
ret += (20.0*math.Sin(6.0*x*pi) + 20.0*math.Sin(2.0*x*pi)) * 2.0 / 3.0 | ||
ret += (20.0*math.Sin(y*pi) + 40.0*math.Sin(y/3.0*pi)) * 2.0 / 3.0 | ||
ret += (160.0*math.Sin(y/12.0*pi) + 320*math.Sin(y*pi/30.0)) * 2.0 / 3.0 | ||
return ret | ||
} | ||
|
||
func transformlng(x, y float64) float64 { | ||
ret := 300.0 + x + 2.0*y + 0.1*x*x + 0.1*x*y + 0.1*math.Sqrt(math.Abs(x)) | ||
ret += (20.0*math.Sin(6.0*x*pi) + 20.0*math.Sin(2.0*x*pi)) * 2.0 / 3.0 | ||
ret += (20.0*math.Sin(x*pi) + 40.0*math.Sin(x/3.0*pi)) * 2.0 / 3.0 | ||
ret += (150.0*math.Sin(x/12.0*pi) + 300.0*math.Sin(x/30.0*pi)) * 2.0 / 3.0 | ||
return ret | ||
} | ||
|
||
func (receiver *GPSUtil) transformlng(x, y float64) float64 { | ||
ret := 300.0 + x + 2.0*y + 0.1*x*x + 0.1*x*y + 0.1*math.Sqrt(math.Abs(x)) | ||
ret += (20.0*math.Sin(6.0*x*pi) + 20.0*math.Sin(2.0*x*pi)) * 2.0 / 3.0 | ||
ret += (20.0*math.Sin(x*pi) + 40.0*math.Sin(x/3.0*pi)) * 2.0 / 3.0 | ||
ret += (150.0*math.Sin(x/12.0*pi) + 300.0*math.Sin(x/30.0*pi)) * 2.0 / 3.0 | ||
return ret | ||
} | ||
|
||
func outOfChina(lat, lng float64) bool { | ||
if lng < 72.004 || lng > 137.8347 { | ||
return true | ||
} | ||
if lat < 0.8293 || lat > 55.8271 { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
func (receiver *GPSUtil) outOfChina(lat, lng float64) bool { | ||
if lng < 72.004 || lng > 137.8347 { | ||
return true | ||
} | ||
if lat < 0.8293 || lat > 55.8271 { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
func transform(lat, lng float64) (float64, float64) { | ||
if outOfChina(lat, lng) { | ||
return 0.0, 0.0 | ||
} | ||
dLat := transformLat(lng-105.0, lat-35.0) | ||
dlng := transformlng(lng-105.0, lat-35.0) | ||
radLat := lat / 180.0 * pi | ||
magic := math.Sin(radLat) | ||
magic = 1 - ee*magic*magic | ||
SqrtMagic := math.Sqrt(magic) | ||
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * SqrtMagic) * pi) | ||
dlng = (dlng * 180.0) / (a / SqrtMagic * math.Cos(radLat) * pi) | ||
mgLat := lat + dLat | ||
mglng := lng + dlng | ||
return mgLat, mglng | ||
} | ||
|
||
func (receiver *GPSUtil) transform(lat, lng float64) []float64 { | ||
if receiver.outOfChina(lat, lng) { | ||
return []float64{lat, lng} | ||
} | ||
dLat := receiver.transformLat(lng-105.0, lat-35.0) | ||
dlng := receiver.transformlng(lng-105.0, lat-35.0) | ||
radLat := lat / 180.0 * pi | ||
magic := math.Sin(radLat) | ||
magic = 1 - ee*magic*magic | ||
SqrtMagic := math.Sqrt(magic) | ||
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * SqrtMagic) * pi) | ||
dlng = (dlng * 180.0) / (a / SqrtMagic * math.Cos(radLat) * pi) | ||
mgLat := lat + dLat | ||
mglng := lng + dlng | ||
return []float64{mgLat, mglng} | ||
} | ||
|
||
// WGS84_To_Gcj02 84 to 火星坐标系 (GCJ-02) World Geodetic System ==> Mars Geodetic System | ||
// @param lat | ||
// @param lng | ||
// @return | ||
func WGS84_To_Gcj02(lat, lng float64) (float64, float64) { | ||
if outOfChina(lat, lng) { | ||
return 0.0, 0.0 | ||
} | ||
dLat := transformLat(lng-105.0, lat-35.0) | ||
dlng := transformlng(lng-105.0, lat-35.0) | ||
radLat := lat / 180.0 * pi | ||
magic := math.Sin(radLat) | ||
magic = 1 - ee*magic*magic | ||
SqrtMagic := math.Sqrt(magic) | ||
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * SqrtMagic) * pi) | ||
dlng = (dlng * 180.0) / (a / SqrtMagic * math.Cos(radLat) * pi) | ||
mgLat := lat + dLat | ||
mglng := lng + dlng | ||
return mgLat, mglng | ||
} | ||
|
||
func (receiver *GPSUtil) WGS84_To_Gcj02(lat, lng float64) []float64 { | ||
if receiver.outOfChina(lat, lng) { | ||
return []float64{lat, lng} | ||
} | ||
dLat := receiver.transformLat(lng-105.0, lat-35.0) | ||
dlng := receiver.transformlng(lng-105.0, lat-35.0) | ||
radLat := lat / 180.0 * pi | ||
magic := math.Sin(radLat) | ||
magic = 1 - ee*magic*magic | ||
SqrtMagic := math.Sqrt(magic) | ||
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * SqrtMagic) * pi) | ||
dlng = (dlng * 180.0) / (a / SqrtMagic * math.Cos(radLat) * pi) | ||
mgLat := lat + dLat | ||
mglng := lng + dlng | ||
return []float64{mgLat, mglng} | ||
} | ||
|
||
// GCJ02_To_WGS84 | ||
// 火星坐标系 (GCJ-02) to WGS84 | ||
// @param lng | ||
// @param lat | ||
// @return | ||
func (receiver *GPSUtil) GCJ02_To_WGS84(lat, lng float64) []float64 { | ||
gps := receiver.transform(lat, lng) | ||
lngtitude := lng*2 - gps[1] | ||
latitude := lat*2 - gps[0] | ||
return []float64{latitude, lngtitude} | ||
} | ||
|
||
/** | ||
* 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换算法 将 GCJ-02 坐标转换成 BD-09 坐标 | ||
* | ||
* @param lat | ||
* @param lng | ||
*/ | ||
func (receiver *GPSUtil) gcj02_To_Bd09(lat, lng float64) []float64 { | ||
x := lng | ||
y := lat | ||
z := math.Sqrt(x*x+y*y) + 0.00002*math.Sin(y*x_pi) | ||
theta := math.Atan2(y, x) + 0.000003*math.Cos(x*x_pi) | ||
templng := z*math.Cos(theta) + 0.0065 | ||
tempLat := z*math.Sin(theta) + 0.006 | ||
gps := []float64{tempLat, templng} | ||
return gps | ||
} | ||
|
||
/** | ||
* * 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换算法 * * 将 BD-09 坐标转换成GCJ-02 坐标 * * @param | ||
* bd_lat * @param bd_lng * @return | ||
*/ | ||
func (receiver *GPSUtil) bd09_To_Gcj02(lat, lng float64) []float64 { | ||
x := lng - 0.0065 | ||
y := lat - 0.006 | ||
z := math.Sqrt(x*x+y*y) - 0.00002*math.Sin(y*x_pi) | ||
theta := math.Atan2(y, x) - 0.000003*math.Cos(x*x_pi) | ||
templng := z * math.Cos(theta) | ||
tempLat := z * math.Sin(theta) | ||
gps := []float64{tempLat, templng} | ||
return gps | ||
} | ||
|
||
/**将WGS84转为bd09 | ||
* @param lat | ||
* @param lng | ||
* @return | ||
*/ | ||
func (receiver *GPSUtil) WGS84_To_bd09(lat, lng float64) []float64 { | ||
gcj02 := receiver.WGS84_To_Gcj02(lat, lng) | ||
bd09 := receiver.gcj02_To_Bd09(gcj02[0], gcj02[1]) | ||
return bd09 | ||
} | ||
|
||
func (receiver *GPSUtil) bd09_To_WGS84(lat, lng float64) []float64 { | ||
gcj02 := receiver.bd09_To_Gcj02(lat, lng) | ||
WGS84 := receiver.GCJ02_To_WGS84(gcj02[0], gcj02[1]) | ||
return WGS84 | ||
} |
Oops, something went wrong.