我正在当地语言的传单地图中获得标记的地址。如何将其更改为英语

问题描述 投票:0回答:1

我的网站上有一张传单地图,如

var map = L.map('map').setView([25.0750853, 54.9475437], 10);

  L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
    attribution: '&copy; <a href="https://osm.org/copyright">OpenStreetMap</a> contributors'
  }).addTo(map);
  marker = new L.marker([25.0750853, 54.9475437], {draggable:'true'});
  marker.on('dragend', function(event){
    var marker = event.target;
    var position = marker.getLatLng();
    marker.setLatLng(new L.LatLng(position.lat, position.lng),{draggable:'true'});
    map.panTo(new L.LatLng(position.lat, position.lng))
    getAddress(position);
  });
  map.addLayer(marker);
  var geocodeService = L.esri.Geocoding.geocodeService();

  function getAddress(position) {
    geocodeService.reverse().latlng(position).run(function (error, result) {
      if (error) {
        return;
      }
      alert(result.address.Match_addr);
    });
  }

这是我的地图代码。当我移动标记时,我想获取位置地址。但是我正在以当地语言获取地址。如何将地址语言更改为英语

leaflet reverse-geocoding geocode
1个回答
0
投票

您需要指定language("eng")才能正常运行

 function getAddress(position) {
    geocodeService.reverse().latlng(position).language("eng") // here make the change
      .run(function(error, result) {
        if (error) {
          return;
        }
        alert(result.address.Match_addr);
      });
  }

<!DOCTYPE html>
<html>

  <head>
    <title>Quick Start - Leaflet</title>

    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
    <script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
    <script src="https://unpkg.com/esri-leaflet"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/perliedman-leaflet-control-geocoder/1.12.1/Control.Geocoder.js"></script>
    <!-- Load Esri Leaflet from CDN -->
    <script src="https://unpkg.com/[email protected]/dist/esri-leaflet.js"></script>

    <!-- Load Esri Leaflet Geocoder from CDN -->
    <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/esri-leaflet-geocoder.css" />
    <script src="https://unpkg.com/[email protected]/dist/esri-leaflet-geocoder.js"></script>
  </head>

  <body>
    <div id="map" style="width: 600px; height: 400px;"></div>
    <script>
      var map = L.map('map').setView([25.0750853, 54.9475437], 10);

      L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
        attribution: '&copy; <a href="https://osm.org/copyright">OpenStreetMap</a> contributors'
      }).addTo(map);
      marker = new L.marker([25.0750853, 54.9475437], {
        draggable: 'true'
      });
      marker.on('dragend', function(event) {
        var marker = event.target;
        var position = marker.getLatLng();
        marker.setLatLng(new L.LatLng(position.lat, position.lng), {
          draggable: 'true'
        });
        map.panTo(new L.LatLng(position.lat, position.lng))
        getAddress(position);
      });
      map.addLayer(marker);
      var geocodeService = L.esri.Geocoding.geocodeService();

      function getAddress(position) {
        geocodeService.reverse().latlng(position).language("eng")
          .run(function(error, result) {
            if (error) {
              return;
            }
            alert(result.address.Match_addr);
          });
      }

    </script>
  </body>

</html>
© www.soinside.com 2019 - 2024. All rights reserved.