[英]Update Google Places API results using javascript
I'm using Google Places API to get location details using javascript. 我正在使用Google Places API使用javascript获取位置详细信息。
var request = {
input: request.term,
componentRestrictions: {country: 'us'},
types: ['geocode']};
service.getPlacePredictions(request, function (predictions, status) {
if (status != 'OK') {
return;
}
response($.map(predictions, function (prediction, i) {
var cty_st = '';
var pred_terms_lnt = prediction.terms.length;
if(pred_terms_lnt >= 3){
cty_st = prediction.terms[pred_terms_lnt - 3].value+', '+prediction.terms[pred_terms_lnt - 2].value;
}
else if(pred_terms_lnt >= 2){
cty_st = prediction.terms[pred_terms_lnt - 2].value;
}
else{
cty_st = prediction.description.replace(", United States", "");
}
return {
label: cty_st,
value: cty_st,
ref: prediction.reference,
id: prediction.id
}
}));
});
I want to show only city and state code from the results fetched and when I search for a location I'm getting duplicate city, state coder in the results. 我只想从获取的结果中显示城市和州代码,当我搜索某个位置时,我得到重复的城市,即结果中的州代码。 I want to remove these duplicates from the results.
我想从结果中删除这些重复项。 How to do that?
怎么做?
From the above results you can see last two results have same city and state code. 从以上结果中,您可以看到最后两个结果具有相同的城市和州代码。 I want to show only once.
我只想显示一次。
代替types: ['geocode']
使用types: ['(cities)']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.