如何prevent谷歌地球codeR从其他国家返回结果 [英] How to prevent google geocoder from returning results from other countries

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

问题描述

我使用谷歌的地理codeR,同时可以选择只从德国返回结果

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

下面是我的函数的相关部分。

Here's the relevant part of my function

    ...
    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);
            }

     ...

但如果我地理code屈夫里

but if i geocode "cuvry"

Google会返回屈夫里,法国

google returns "Cuvry, France"

而这绝对不是在德国。

我如何prevent谷歌地球$ C $从返回结果不在德国CR?
我的意思是返回,回调不检查,如果国家 - code不匹配。

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

推荐答案

当我改成了
地理coder.geo code({地址:地址,componentRestrictions:{国: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.

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

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