Git Product home page Git Product logo

gobaidumap's Introduction

gobaidumap

百度地图接口调用 golang 版。支持GEO、地址双向获取,IP获取地址。

外国 IP 什么的,百度不支持。

练习 golang 时写的,见笑啦!

感谢 @zzdboy 的测试的反馈!

安装/更新

go get -u github.com/menduo/gobaidumap

注意

请到百度地图开发者中心申请自己的 App Key。代码里的常量 ak 中保证永久有效,且配额经常被大家耗光(应该是大家测试着玩呢?)。

简单说,你自己去申请一个就万事大吉啦!可以通过环境变量或者 BaiduMapClient 构造方式自定义。

使用

package main

import (
	"fmt"
	"github.com/menduo/gobaidumap"
)

func main() {

	lat := "40.069462"
	lng := "116.346364"

	bc := gobaidumap.NewBaiduMapClient(gobaidumap.GetDefaultAK())

	// 从坐标到地址
	GEOToAddress, err := bc.GetAddressViaGEO(lat, lng)

	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println("坐标到地址:", GEOToAddress)
		fmt.Println("坐标到地址 - 地址", GEOToAddress.Result.AddressComponent)
		fmt.Println("\n")
	}

	// 从地址到坐标
	address := "百度大厦"
	addressToGEO, err := gobaidumap.GetGeoViaAddress(address)
	if err != nil {
		fmt.Println(err)
	} else {

		fmt.Println("从地址到坐标 - All", addressToGEO)
		fmt.Println("从地址到坐标 - Lat", addressToGEO.Result.Location.Lat)
		fmt.Println("从地址到坐标 - Lng", addressToGEO.Result.Location.Lng)
		fmt.Println("\n")
	}

	// 从IP到地址
	ipAddress := "202.198.16.3"
	IPToAddress, err := gobaidumap.GetAddressViaIP(ipAddress)

	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println("从IP到地址:", IPToAddress)
		fmt.Println("从IP到地址 - 地址:", IPToAddress, IPToAddress.Content.Address)
		fmt.Println("\n")
	}

	// 从IP到地址
	ipAddress = "8.8.8.8"
	IPToAddress, err = gobaidumap.GetAddressViaIP(ipAddress)

	if err != nil {
		fmt.Println("从IP到地址,err !=nil:", err)
		fmt.Println("\n")
	} else {
		fmt.Println("从IP到地址:", IPToAddress)
		fmt.Println("从IP到地址 - 地址:", IPToAddress, IPToAddress.Content.Address)
		fmt.Println("\n")
	}
}

CHANGELOG

2019-01-24

  • 调整 代码结构
  • 新增 gobaidumap.NewBaiduMapClient(创建 BaiduMapClient )。
  • 新增 自定义 ak 支持(环境变量,或 client 构造传参 )
  • 调整 默认 ak 的获取方式,优先从环境变量读取,没有从取默认 ak(这个 ak 的资源配额已经被大家耗光了……)

联系 & 反馈

shimenduo at gmail dot com

https://github.com/menduo/gobaidumap/issues

gobaidumap's People

Contributors

bitdeli-chef avatar menduo avatar shajiquan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

gobaidumap's Issues

Bugs

有bug请在这里反馈。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.