10 Star 29 Fork 7

menduo / gobaidumap

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

gobaidumap

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

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

练习 golang 时写的,见笑啦!

感谢 @zzdboy 的测试的反馈!

安装/更新

go get -u github.com/menduo/gobaidumap

注意

请到百度地图开发者中心申请自己的 App Key,下方的 key 是百度提供的,不保证永远有效。

使用

package main

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

func main() {

    var lat string = "40.069462"
    var lng string = "116.346364"

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

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

    // 从地址到坐标
    address := "百度大厦"
    addressToGEO, err := baidumap.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 := baidumap.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 = baidumap.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")
    }
}

联系 & 反馈

shimenduo at gmail dot com

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

The MIT License (MIT) Copyright (c) 2014 沙吉泉 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

百度地图接口调用 golang 版。支持GEO、地址双向获取,IP获取地址。Baidu Map for go lang. 展开 收起
Go
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Go
1
https://gitee.com/menduo/gobaidumap.git
git@gitee.com:menduo/gobaidumap.git
menduo
gobaidumap
gobaidumap
master

搜索帮助