我正在使用 yahoo 的 placemaker 从文本中提取位置名称。从这里我得到一个回调函数,它给了我 2 种不同类型的数组。
这是正在使用的代码,但我无法使用任何我想要的值。
Placemaker.getPlaces(text,function(o){
if (typeof o.match!=='undefined' && o.match.length==1){
latitude=o.match.place.centroid.latitude, longitude=o.match.place.centroid.longitude;
console.log(latitude,longitude);}
if(typeof o.match !=='undefined'&& o.match.length==2){
latitude=o[match].place.centroid.latitude,
longitude=o[match].place.centroid.longitude;
console.log(latitude,longitude);
}
第一个数组看起来像这样
({
match: {
place: {
woeId: "29007292",
type: "Town",
name: "Jubila, West Bengal, IN",
centroid: {
latitude: "23.1626",
longitude: "87.7889"
}
},
reference: [{
woeIds: "29007292",
placeReferenceId: "2",
placeIds: "1",
start: "14",
end: "20",
isPlaintextMarker: "1",
text: "jubila",
type: "plaintext",
xpath: null
}, {
woeIds: "29007292",
placeReferenceId: "3",
placeIds: "1",
start: "82",
end: "88",
isPlaintextMarker: "1",
text: "jubila",
type: "plaintext",
xpath: null
}]
}
})
另一个像这样
({
match: [{
place: {
woeId: "23424950",
type: "Country",
name: "Spain",
centroid: {
latitude: "39.8949",
longitude: "-2.98831"
}
},
reference: {
woeIds: "23424950",
placeReferenceId: "1",
placeIds: "1",
start: "64",
end: "70",
isPlaintextMarker: "1",
text: "Espa\xF1a",
type: "plaintext",
xpath: null
}
}, {
place: {
woeId: "24865675",
type: "Continent",
name: "Europe",
centroid: {
latitude: "52.9762",
longitude: "7.85784"
}
},
reference: {
woeIds: "24865675",
placeReferenceId: "2",
placeIds: "2",
start: "93",
end: "99",
isPlaintextMarker: "1",
text: "Europa",
type: "plaintext",
xpath: null
}
}]
})