Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
136 views
in Technique[技术] by (71.8m points)

javascript - Convert Latitude Longtitude to an Address in a map

my code: (i used ArcGIS for the map code https://developers.arcgis.com/javascript/3/jssamples/widget_locate.html )

<!DOCTYPE html>
<html> 
  <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no" />
    <title>OpenStreetMap</title> 
    <link rel="stylesheet" href="https://js.arcgis.com/3.35/esri/css/esri.css">
    <style>
      html, body, #esri-map-container {
        padding: 0px;
        margin: 0px;
        height: 100%;
        width: 800px;
        height: 500px;
      }
      #LocateButton {
      position: absolute;
      top: 95px;
      left: 20px;
      z-index: 50;
    }
    </style>
    <script src="https://js.arcgis.com/3.35/"></script>
  <script>
    var map; 

    require([
      "esri/map", 
      "esri/dijit/LocateButton",
      "dojo/domReady!"
    ], function(Map, LocateButton)  
    {
      map = new Map("map", {
        center: [-56.049, 38.485],
        zoom: 3,
        basemap: "streets"
      });
            
      geoLocate = new LocateButton({
        map: map
      }, "LocateButton");
      geoLocate.startup();

      geoLocate.on('locate', (data) => {
                console.log(data);
            });
    });
  </script>

  </head>  
  <body>
    <div id="map" class="map">
    <div id="LocateButton"></div>
  </body> 
</html>

So i get coordinates with:

geoLocate.on('locate', (data) => {
                console.log(data);
            });

and then i want to convert them into an address. with the address i want to give them information about the city they live in. since i want to get an address on my specific country (Israel) which is not big, the idea is maybe to write a table with longitude and latitude and the main citys and when some user use his locate button, i will find which from the table is the closest to him, and then return the data i already written in a table or something like this so my question is: is there a way to convert my long and latitude to the address with what i have written? or maybe is it better for me to do the second idea with prewritten data. i don't know how to do those, so i would like to get some directions on where to start or how to look for it. thanks.

question from:https://stackoverflow.com/questions/65651488/convert-latitude-longtitude-to-an-address-in-a-map

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In your second method, you have to use rectangular boundaries of all cities, you can search for it. but if you want direct from long lat to location. use google map cloud APIs, visit their website to learn more.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...