我有一个Geo JSON文件,我能够读取它。现在的问题是我不知道如何从这个json文件中找到lat,lng。这是json文件对象
["division": dhaka, "city_count": 19, "geojson": <__NSArrayI 0x280fe4b00>(
{
"city_count" = 5;
coordinate = {
features = (
{
geometry = {
coordinates = (
(
(
"90.35087585449219",
"23.87767555995429"
),
(
"90.35293579101562",
"23.87783252903805"
),
(
"90.35465240478516",
"23.87940220940522"
),
(
"90.33697128295898",
"23.77372029600594"
),
(
"90.33422470092773",
"23.77434867446102"
),
(
"90.33353805541992",
"23.77670506662895"
),
(
"90.33662796020508",
"23.77874723863914"
),
(
"90.3350830078125",
"23.78173189388713"
),
(
"90.33473968505859",
"23.78471648062244"
),
(
"90.33731460571289",
"23.78691560595149"
),
(
"90.33851623535156",
"23.78958592240541"
),
(
"90.33885955810547",
"23.79225618399747"
),
(
"90.33920288085938",
"23.79524052908337"
),
(
"90.33868789672852",
"23.79775360862461"
),
(
"90.34109115600586",
"23.79916719450499"
),
(
"90.34212112426758",
"23.80183725920138"
),
(
"90.34126281738281",
"23.80544961231463"
),
(
"90.33920288085938",
"23.80890481258195"
),
(
"90.33817291259766",
"23.81204582395521"
),
(
"90.33937454223633",
"23.8144015326186"
),
(
"90.340576171875",
"23.81644311221666"
),
(
"90.33920288085938",
"23.81801353621191"
),
(
"90.33576965332031",
"23.81864170048991"
),
(
"90.33645629882812",
"23.82115432719981"
),
(
"90.33748626708984",
"23.82288172984448"
),
(
"90.33988952636719",
"23.82460910949492"
),
(
"90.34160614013672",
"23.82617943467697"
),
(
"90.34246444702148",
"23.82869191543645"
),
(
"90.34040451049805",
"23.83104732195727"
),
(
"90.33851623535156",
"23.83340268570913"
),
(
"90.33885955810547",
"23.83638608505927"
),
(
"90.33971786499023",
"23.83842731875501"
),
(
"90.34074783325195",
"23.84093956227041"
),
(
"90.33851623535156",
"23.84470783627317"
),
(
"90.33645629882812",
"23.84706295190193"
),
(
"90.33714294433594",
"23.84926102121543"
),
(
"90.33851623535156",
"23.85193005526536"
),
(
"90.34109115600586",
"23.85507002494591"
),
(
"90.34383773803711",
"23.85773893934751"
),
(
"90.34675598144531",
"23.86025080855958"
),
(
"90.3486442565918",
"23.86386153521903"
),
(
"90.35036087036133",
"23.8665302684893"
),
(
"90.35053253173828",
"23.86998384167086"
),
(
"90.35053253173828",
"23.87296639892589"
),
(
"90.35018920898438",
"23.87516402872517"
),
(
"90.35087585449219",
"23.87767555995429"
)
)
);
type = Polygon;
};
properties = {
};
type = Feature;
}
);
type = FeatureCollection;
}]
假设我尝试找到此“ 90.35293579101562”, “ 23.87783252903805” lat lng如何找到此文件或如何知道此json文件中包含此坐标。
谢谢
答案 0 :(得分:1)
要找出元素是否存在于元素数组中,您可以简单地使用.contains()
函数,
例如,如果它像数组一样简单,则可以执行此操作,
let foo = [1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,8]
if foo.contains(1) {
print("Yes it does")
}
但是,如果您获得了一些自定义对象的数组,例如long & lat
,
您需要先执行2步
1-您必须确认遵守Equatable
协议
2-您必须添加扩展来实现==
运算符,然后只需使用相同的功能并遵守以下代码。
struct CustomLocation: Equatable {
var long: String
var lat: String
}
extension CustomLocation {
static func == (lhs: CustomLocation, rhs: CustomLocation) -> Bool {
return lhs.long == rhs.long && lhs.lat == rhs.long
}
}
let location1 = CustomLocation(long: "1,1", lat: "1,1") // test object
let location2 = CustomLocation(long: "2,3", lat: "2,3") // test object
let myWantedLocation = CustomLocation(long: "5,5", lat: "5,5") //the wanted object
let locations = [location1, location1, location1, location2, location2, location2, myWantedLocation] // an array of the same object include one value from my wanted object
//a check up test
if locations.contains(myWantedLocation) {
print("Yes It Does") // prints out yes it does
}