{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[115.39426410200747,22.94784224837025],[115.39525110167136,22.945787289830454],[115.3979121019858,22.943653331808937],[115.39831410166869,22.942887347290936],[115.082750101603,22.812965923132766],[115.08244910220242,22.813400915157258],[115.08212710198719,22.81377690712516]]]},"properties":{"name":"赤石镇"}},{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[115.13054010191735,22.80305511978658],[115.12980310160035,22.802909122278039],[115.12847110215496,22.802646127953943],[115.12109910203034,22.800059178645669],[115.1083111015656,22.794836281526125],[115.10779010205698,22.79469128473647]]]},"properties":{"name":"鮜门镇"}},{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[115.04624110150752,22.767672818261745],[115.04608510187191,22.76729882545456],[115.04608510187191,22.766747836769487],[115.04617210191057,22.766133848941327],[115.0461461019713,22.765538860311879],[115.04585810209123,22.763833894370273],[115.04568410201392,22.762426921957198]]]},"properties":{"name":"小漠镇"}}]},用JQuery判断(115.079862,22.880832)这个经纬度属于上面josn文件里的哪个name
时间: 2023-08-22 13:10:46 浏览: 47
以下是使用JQuery判断(115.079862,22.880832)这个经纬度属于上面json文件里的哪个name的代码:
```javascript
var json = {"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[115.39426410200747,22.94784224837025],[115.39525110167136,22.945787289830454],[115.3979121019858,22.943653331808937],[115.39831410166869,22.942887347290936],[115.082750101603,22.812965923132766],[115.08244910220242,22.813400915157258],[115.08212710198719,22.81377690712516]]]},"properties":{"name":"赤石镇"}},{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[115.13054010191735,22.80305511978658],[115.12980310160035,22.802909122278039],[115.12847110215496,22.802646127953943],[115.12109910203034,22.800059178645669],[115.1083111015656,22.794836281526125],[115.10779010205698,22.79469128473647]]]},"properties":{"name":"鮜门镇"}},{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[115.04624110150752,22.767672818261745],[115.04608510187191,22.76729882545456],[115.04608510187191,22.766747836769487],[115.04617210191057,22.766133848941327],[115.0461461019713,22.765538860311879],[115.04585810209123,22.763833894370273],[115.04568410201392,22.762426921957198]]]},"properties":{"name":"小漠镇"}}]};
var point = [115.079862,22.880832];
// 遍历features数组
$.each(json.features, function(index, feature) {
// 判断点是否在多边形内
if (turf.booleanPointInPolygon(point, feature.geometry)) {
console.log(point + " 属于 " + feature.properties.name);
}
});
```
代码中使用了Turf.js库的`booleanPointInPolygon`方法来判断点是否在多边形内。遍历json文件中的features数组,如果点在某个多边形内,则输出该多边形的name属性。根据上述代码,(115.079862,22.880832)这个经纬度属于"赤石镇"。
阅读全文