Helps you locate whether a point(latitude and longitude) is in the GeoJson map
Find location info by latitude and longitude
Compare the query efficiency of different geojson files
You can find them for certain countries or regions on certain websites. For example, you can find geojson file of China on Aliyun
Another idea is try to find it on GitHub or Google
Otherwise, you need to do:
- First download a shape file, on websites like gadm or naturalearth
- Generate geojson file by shape file on website mapshaper, import your shape file and you can use
simplify
to control the size of your geojson file, finally export it.
go get github.com/linvon/golang-geohelper
Prepare an geojson file, and get the key
like "name"
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [125.6, 10.1]
},
"properties": {
"name": "Dki Jakarta"
}
}
Code and Run
m, err := geohelper.NewGeoMap("highgeo.json", "name") // file, key
if err != nil {
log.Fatalln(err)
}
provinceName := m.FindLoc(-6.196893, 106.830407)
fmt.Println(provinceName)
帮助你判断一个用经纬度表示的点是否在 geojson 地图中
通过经纬度反查地理位置信息
比较不同的 geojson 文件查询效率
你可以在某些网站上找到某些国家或地区的 geojson 文件。比如,你可以在阿里云的工具站上找到中国的 geojson 文件
另一个方法是尝试在 GitHub 或者 Google 上面找到相关文件
其他情况下,你需要这么做:
- 首先下载一个形状文件, 可以从这些网站上下载: gadm 或 naturalearth
- 在 mapshaper 上通过形状文件生成 geojson 文件, 导入形状文件后你可以使用简化操作控制你的 geojson 文件大小,最后导出文件
go get github.com/linvon/golang-geohelper
准备好一个 geojson 文件,并找到其中表示名称的 key
比如 "name"
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [125.6, 10.1]
},
"properties": {
"name": "Dki Jakarta"
}
}
编码并运行
m, err := geohelper.NewGeoMap("highgeo.json", "name") // file, key
if err != nil {
log.Fatalln(err)
}
provinceName := m.FindLoc(-6.196893, 106.830407)
fmt.Println(provinceName)