[英]Leaflet geosearch: return lat/lng from address found event
我使用很棒的Leaflet插件进行地理编码,例如https://github.com/smeijer/L.GeoSearch
虽然这些功能非常适合在找到时在地图上显示地址位置,但我也希望能够将结果中的坐标用于我包含在地图中的其他函数(例如,我编写了一个可从中找到附近点的函数)基于从Leaflet的内置locate
函数触发的locationfound
事件的数据层)。
我知道答案(可能)在于从geosearch插件访问事件,但这超出了我的技能。 任何帮助将非常欢迎。
L.GeoSearch
插件会在您的地图实例上触发事件。 您需要侦听geosearch_foundlocations
事件。 触发事件时返回的对象拥有一个Locations
属性,该属性包含具有L.GeoSearch.Result
对象的数组。 每个对象都有四个属性。 Label
, X
, Y
和bounds
代码示例:
map.on('geosearch_foundlocations', function (e) {
e.Locations.forEach(function (Location) {
// Location.Label = full address
// Location.X = longitude
// Location.Y = latitude
// Location.bounds = boundaries
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.