[英]Leaflet geosearch: return lat/lng from address found event
I use great Leaflet plugins for geocoding such as https://github.com/smeijer/L.GeoSearch 我使用很棒的Leaflet插件进行地理编码,例如https://github.com/smeijer/L.GeoSearch
While these are perfect for showing address locations on the map when found, I would also like to be able to use the coordinates from the result to other functions that I have included in my map (eg I've written one which finds nearby points from a data layer based on the locationfound
event fired from Leaflet's inbuilt locate
function). 虽然这些功能非常适合在找到时在地图上显示地址位置,但我也希望能够将结果中的坐标用于我包含在地图中的其他函数(例如,我编写了一个可从中找到附近点的函数)基于从Leaflet的内置
locate
函数触发的locationfound
事件的数据层)。
I know the answer (probably) lies in accessing the events from the geosearch plugin, but that's a bit beyond my skills at the moment. 我知道答案(可能)在于从geosearch插件访问事件,但这超出了我的技能。 Any help would be very welcome.
任何帮助将非常欢迎。
The L.GeoSearch
plugin fires it's events on your map instance. L.GeoSearch
插件会在您的地图实例上触发事件。 You'll need to listen for the geosearch_foundlocations
event. 您需要侦听
geosearch_foundlocations
事件。 The object that's returned when the event is fired holds a Locations
property which contains an array with L.GeoSearch.Result
objects. 触发事件时返回的对象拥有一个
Locations
属性,该属性包含具有L.GeoSearch.Result
对象的数组。 Each object has four properties; 每个对象都有四个属性。
Label
, X
, Y
and bounds
Label
, X
, Y
和bounds
Example in code: 代码示例:
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.