Skip to content

Helps you locate whether a point(latitude and longitude) is in the GeoJson map/find location by latitude and longitude 判断经纬度表示的点是否在geojson表示的map中/经纬度反查区域、城市地址

Notifications You must be signed in to change notification settings

linvon/golang-geohelper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Golang-GeojsonHelper

中文文档

What is this?

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

What you need

GeoJson Map (Wiki)

How to get GeoJson File?

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:

  1. First download a shape file, on websites like gadm or naturalearth
  2. 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.

How to use

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 Map (Wiki)

如何获取 GeoJson 文件?

你可以在某些网站上找到某些国家或地区的 geojson 文件。比如,你可以在阿里云的工具站上找到中国的 geojson 文件

另一个方法是尝试在 GitHub 或者 Google 上面找到相关文件

其他情况下,你需要这么做:

  1. 首先下载一个形状文件, 可以从这些网站上下载: gadmnaturalearth
  2. 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)

About

Helps you locate whether a point(latitude and longitude) is in the GeoJson map/find location by latitude and longitude 判断经纬度表示的点是否在geojson表示的map中/经纬度反查区域、城市地址

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages