![](/img/trans.png)
[英]In a Chrome Extension, how can I accurately retrieve the user's region/locale/country from their Chrome browser?
[英]How can I retrieve result from my country in here maps?
我使用此功能來檢索目標用戶搜索的結果,但是這會從世界上獲取所有結果,我該如何區分某些國家/地區的結果
function getPlace() {
setLoadingIcons(true);
var places = platform.getPlacesService(),
entryPoint = H.service.PlacesService.EntryPoint,
txtSearch = document.getElementById('txtSearch');
places.request(entryPoint.SEARCH, { 'at': _HEREmap.getCenter().lat + ',' + _HEREmap.getCenter().lng, 'q': txtSearch.value, 'size': 5 }, function (response) {
var items = response.results.items;
var placeHTML = '<div><a href="#" onclick="return showMapForDistination({LAT}, {LNG});"> <input hidden name="lat" value="{LAT}"><input hidden name="lat" value="{LNG}">{TITLE} <img src="Images/navigation Icon.png" id="arr" width="15" /> </a></div>';
var html = '';
for (var i = 0; i < items.length; i++) {
html += placeHTML.replace("{TITLE}", items[i].title).replace("{LAT}", items[i].position[0]).replace("{LNG}", items[i].position[1]);
}
document.getElementById('divSearchResult').innerHTML = html + '<div id="divCnclBtn"><img src="Images/Cancel Button.png" id="cnclBtn" onclick="onSearchTextBlur();"></div>';
document.getElementById('divSearchResult').style['display'] = 'block';
setLoadingIcons(false);
}, function (resp) {
//console.log('ERROR: ' + resp);
setLoadingIcons(false);
});
}
因此,據我在Places API參考中所說的,這很難做到...
首先,不是使用“ in” ,而是使用帶有邊界框 (即國家/地區的邊界框)的“ in”來進行粗略過濾。 得到結果時,請查看每個地方結果的address屬性,並按address.country (或address.countryCode)進行過濾。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.