【问题标题】:How do I get the address with the latitude and longitude?如何获取带有经纬度的地址?
【发布时间】:2021-04-30 07:37:53
【问题描述】:

我是 reactjs 新手,想试试地理位置。我已经可以显示经度和纬度,但是如何在不使用 Google Maps API 的情况下获取地址? (要使用 Google Maps API,我需要一个我没有的结算帐户)

class Map extends Component {
  constructor(props) {
    super(props);
    this.state = {
      latitude: null,
      longitude: null,
      userAddress: null,
    };

    this.getLocation = this.getLocation.bind(this);
    this.getCoordinates = this.getCoordinates.bind(this);
    }

  getLocation() {
    if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(
        this.getCoordinates,
        this.handleLocationErrors
      );
    } else {
      alert("Geolocation not supported ");
    }
  }

  getCoordinates(position) {
    this.setState({
      latitude: position.coords.latitude,
      longitude: position.coords.longitude,
    });
  }

  render() {
    return (
      <div>
        <Button onClick={this.getLocation}
        >
          Get Coordinates
        </Button>
        <p>Latitude: {this.state.latitude}</p>
        <p>Longtitude: {this.state.longitude}</p>
        <p>Address: {this.state.userAddress}</p>
      </div>
    );
  }
}

【问题讨论】:

标签: reactjs geolocation


【解决方案1】:

大多数服务都要求您注册或付费。如果您只进行几次搜索,它是免费的

【讨论】:

  • 那么,没有别的办法了吗?我已经阅读了有关地理编码 API 的信息,您可以在其中将纬度和经度转换为人类可读的地址,并且它需要一个 API 密钥,并且为了拥有它,需要一个计费帐户。我只是想知道是否有另一种方式我无需输入结算帐户即可使用 API
  • 你以前可以这样做,但后来人们向它发送垃圾邮件,他们需要一个注册密钥。除非您有大量查询,否则不会向您收取任何费用
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-12-02
  • 1970-01-01
  • 1970-01-01
  • 2013-07-04
  • 2014-06-14
  • 1970-01-01
相关资源
最近更新 更多