Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

javascript - position on Map then i want to give certain details on the city he lives in

I need a direction, 'cause I don't know how to look for it, or basically how to do that. Every time a user presses a locate button it will locate his position (already done this part) And then, I want to give certain details about his city (in my case, I want to give corona details of people amount that are infected in the city area) for example: so lets say the user lives in new york, and then he clicks on locate position, it gives him the amount of sick people in his area. i used this website for my code: https://developers.arcgis.com/javascript/3/jssamples/widget_locate.html my code:

<!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();

    });
  </script>

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

So yeah, I don't know where to search really, if you can direct me or help me out figuring how am I supposed to do that.

question from:https://stackoverflow.com/questions/65626550/position-on-map-then-i-want-to-give-certain-details-on-the-city-he-lives-in

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

1 Answer

0 votes
by (71.8m points)

You can get some information data about the location detected by using the 'locate' event. In there you will find the coordinates of the location and much more. I personally tried to convert coordinates to address but there is not much ArcGIS support right now. If you find a way through Google's API maybe you will be able to finally get the city through the coordinates ArcGIS gives you.

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

You will find a working example of the event I mentioned above here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...