小编Fil*_*vic的帖子

打开图层地图,有经纬度获取地址

我正在尝试使用经度和纬度获取地址(城市、邮政编码、街道地址),但我不知道如何获取。我正在使用开放图层,当我点击地图的一部分时,会得到该位置的经度和纬度。有人对此有解决方案吗?

<!DOCTYPE html>
<html>
<head>
  <title>Mouse Position</title>
  <link rel="stylesheet" href="https://openlayers.org/en/v4.1.0/css/ol.css" type="text/css">
  <script src="https://openlayers.org/en/v4.1.0/build/ol.js"></script>
</head>
<body>
<div id="map" class="map"></div>
<script>
  var map = new ol.Map({
    layers: [
      new ol.layer.Tile({
        source: new ol.source.OSM()
      })
    ],
    target: 'map',
    view: new ol.View({
      center: [2918616.660738325,4873187.634331534],
      zoom: 19
    })
  });
 
   map.on('click', function (evt) {
    var coord = ol.proj.toLonLat(evt.coordinate);
    alert(coord);
  });
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

html javascript openlayers openlayers-3

6
推荐指数
1
解决办法
4363
查看次数

标签 统计

html ×1

javascript ×1

openlayers ×1

openlayers-3 ×1