如何防止谷歌地理编码器从其他国家返回结果 [英] How to prevent google geocoder from returning results from other countries

查看:20
本文介绍了如何防止谷歌地理编码器从其他国家返回结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用谷歌地理编码器,可选择仅返回来自德国的结果

I'm using the google geocoder with an option to only return results from Germany

这是我函数的相关部分

    ...
    var geocoder = new google.maps.Geocoder();
    geocoder.geocode({"address":address,"region":"DE" }, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            if (results[0].geometry.location) {
                completeGeo(results[0],address);
            } else {
                completeGeo(null,address);
            }

     ...

但如果我也对cuvry"进行地理编码,则会找到德国的那条街道

but if i geocode "cuvry" too find that street in germany

google 返回例如Cuvry, France",它在区域参数之外

google returns for example "Cuvry, France" which is outside of the region parameter

如何防止 google geocoder 返回不在某个国家/地区的结果?我的意思是返回,如果国家/地区代码匹配,则不检查回调.

How can I prevent google geocoder from returning results that are not in a certain Country? I mean return, not check in callback if country-code is matching.

推荐答案

当我把它改成geocoder.geocode({"address":address, "componentRestrictions":{"country":"DE"} },对于德国,我的搜索结果找到了越南.

When I changed it to geocoder.geocode({"address":address, "componentRestrictions":{"country":"DE"} }, for germany my search results found vietnam.

我已将其更改为:

geocoder.geocode( {'address':address + ', Deutschland'}, function(results, status)

这适用于自己语言的国家/地区名称.

This works fine with countries name in own language.

这篇关于如何防止谷歌地理编码器从其他国家返回结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆