1

I have successfully implemented ESRI's JavaScript API's LocateButton widget. I can zoom to my current location on-click. However, I've failed finding a method to return the X,Y coordinates of the location where it zooms.

Any advice or suggested readings? I'm new to JS but could I use something like an on-click event to return the values? How would I query them? Thanks!

I've included the code snippet below:

var testSymbol = new esri.symbol.PictureMarkerSymbol({
   "angle": 0,
   "xoffset": 0,
   "yoffset": 12,
   "type": "esriPMS",
   "url": "http://static.arcgis.com/images/Symbols/Basic/BlackStickpin.png",
   "contentType": "image/png",
   "width": 24,
   "height": 24
});

geoLocate = new LocateButton({
    map: map,
    highlightLocation: true,
    symbol: testSymbol
}, "LocateButton");
geoLocate.startup();
4

2 回答 2

0

文档中的关键行是这样的:

这个小部件使用地理定位 API 来查找用户的当前位置。

地理定位 API 不是特定于 ESRI 的东西,它是 Javascript - LocateButton 只是地理定位库的漂亮包装。MDN 有一些关于使用地理定位的好文档,特别是您正在寻找该getCurrentPosition功能:

navigator.geolocation.getCurrentPosition(function(position) {
  do_something(position.coords.latitude, position.coords.longitude);
});
于 2014-05-23T00:31:25.060 回答
0

您还可以订阅 LocateButton 小部件的“定位”事件。通过帮助

于 2015-06-22T07:42:55.003 回答