如何限制Google Maps地理编码器?

如何解决如何限制Google Maps地理编码器?

我有一个网页,允许用户在输入中键入位置并找到我公司的哪些物理位置最近。大多数情况下都有效。我们在所有营业地点都有LatLng;我们将用户的输入发送到Google Geocoding API,并从那里获取LatLng来找到最接近的。

我正在尝试解决用户不太明确时出现的问题。我们所有的地点都在德克萨斯州,因此,如果用户在输入中输入“ paris”,我希望Geocoding API可以返回德克萨斯州巴黎的搜索结果。不幸的是,该输入仅返回一个结果,而不是在埃菲尔铁塔上戴着牛仔帽的结果。

我已经阅读过有关视口偏移和区域偏移的内容;它们看起来像我所需要的,但是却没有按我期望的那样工作。 https://maps.googleapis.com/maps/api/geocode/json?address=paris&key=MY_KEY&region=ushttps://maps.googleapis.com/maps/api/geocode/json?address=paris&key=MY_KEY&bounds=25.837377,-106.645646|36.500704,-93.508292(以及两个参数的组合)仅返回法国巴黎。有人可以建议吗?

解决方法

您可以使用&components=country:US

将地址解析器限制在美国

请参阅文档中的component filtering

https://maps.googleapis.com/maps/api/geocode/json?address=paris&components=country:US&key=MY_KEY

返回:

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "Lamar County","short_name" : "Lamar County","types" : [ "administrative_area_level_2","political" ]
            },{
               "long_name" : "Texas","short_name" : "TX","types" : [ "administrative_area_level_1",{
               "long_name" : "United States","short_name" : "US","types" : [ "country","political" ]
            }
         ],"formatted_address" : "Lamar County,TX,USA","geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 33.9430568,"lng" : -95.3080719
               },"southwest" : {
                  "lat" : 33.3776528,"lng" : -95.857738
               }
            },"location" : {
               "lat" : 33.75694,"lng" : -95.6457951
            },"location_type" : "APPROXIMATE","viewport" : {
               "northeast" : {
                  "lat" : 33.9430568,"lng" : -95.857738
               }
            }
         },"place_id" : "ChIJf6k5FFj_SoYRwuSdUP31HL0","political" ]
      },{
         "address_components" : [
            {
               "long_name" : "United States","formatted_address" : "United States","geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 71.5388001,"lng" : -66.885417
               },"southwest" : {
                  "lat" : 18.7763,"lng" : 170.5957
               }
            },"location" : {
               "lat" : 37.09024,"lng" : -95.712891
            },"viewport" : {
               "northeast" : {
                  "lat" : 71.5388001,"lng" : 170.5957
               }
            }
         },"place_id" : "ChIJCzYy5IS16lQRQrfeQ5K5Oxw",{
         "address_components" : [
            {
               "long_name" : "156","short_name" : "156","types" : [ "street_number" ]
            },{
               "long_name" : "Paris Street","short_name" : "Paris St","types" : [ "route" ]
            },{
               "long_name" : "Kansas City","short_name" : "KCMO","types" : [ "locality",{
               "long_name" : "Carroll Township","short_name" : "Carroll Township","types" : [ "administrative_area_level_3",{
               "long_name" : "Platte County","short_name" : "Platte County",{
               "long_name" : "Missouri","short_name" : "MO",{
               "long_name" : "64153","short_name" : "64153","types" : [ "postal_code" ]
            }
         ],"formatted_address" : "156 Paris St,Kansas City,MO 64153,"geometry" : {
            "location" : {
               "lat" : 39.3044129,"lng" : -94.7207093
            },"location_type" : "ROOFTOP","viewport" : {
               "northeast" : {
                  "lat" : 39.30576188029149,"lng" : -94.71936031970849
               },"southwest" : {
                  "lat" : 39.30306391970849,"lng" : -94.72205828029151
               }
            }
         },"place_id" : "ChIJg_6e7QZewIcRDuO25dr6ddg","plus_code" : {
            "compound_code" : "873H+QP Kansas City,MO,"global_code" : "86F7873H+QP"
         },"types" : [ "establishment","finance","point_of_interest","post_office" ]
      },{
         "address_components" : [
            {
               "long_name" : "Paris","short_name" : "Paris",{
               "long_name" : "Lamar County","formatted_address" : "Paris,"geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 33.7383781,"lng" : -95.435455
               },"southwest" : {
                  "lat" : 33.6118529,"lng" : -95.62792789999999
               }
            },"location" : {
               "lat" : 33.6609389,"lng" : -95.55551299999999
            },"viewport" : {
               "northeast" : {
                  "lat" : 33.7383781,"lng" : -95.62792789999999
               }
            }
         },"place_id" : "ChIJmysnFgZYSoYRSfPTL2YJuck",{
         "address_components" : [
            {
               "long_name" : "Edgar County","short_name" : "Edgar County",{
               "long_name" : "Illinois","short_name" : "IL","formatted_address" : "Edgar County,IL,"geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 39.88299200000001,"lng" : -87.53164
               },"southwest" : {
                  "lat" : 39.476646,"lng" : -87.96880899999999
               }
            },"location" : {
               "lat" : 39.71312229999999,"lng" : -87.77633329999999
            },"viewport" : {
               "northeast" : {
                  "lat" : 39.88299200000001,"lng" : -87.96880899999999
               }
            }
         },"place_id" : "ChIJkST6Ms69cogRCAPGWoBqOUQ",{
               "long_name" : "Lane County","short_name" : "Lane County",{
               "long_name" : "Oregon","short_name" : "OR",{
               "long_name" : "97390","short_name" : "97390",OR 97390,"geometry" : {
            "location" : {
               "lat" : 44.2526208,"lng" : -123.7706633
            },"viewport" : {
               "northeast" : {
                  "lat" : 44.2606124,"lng" : -123.7546559
               },"southwest" : {
                  "lat" : 44.2446281,"lng" : -123.7866707
               }
            }
         },"place_id" : "ChIJleXtq1KjwVQRLiSkFazeFHU",{
         "address_components" : [
            {
               "long_name" : "Jordan","short_name" : "Jordan","types" : [ "colloquial_area",{
               "long_name" : "Washington Township","short_name" : "Washington Township",{
               "long_name" : "Daviess County","short_name" : "Daviess County",{
               "long_name" : "Indiana","short_name" : "IN",{
               "long_name" : "47501","short_name" : "47501","formatted_address" : "Jordan,Washington Township,IN 47501,"geometry" : {
            "location" : {
               "lat" : 38.6886591,"lng" : -87.206957
            },"viewport" : {
               "northeast" : {
                  "lat" : 38.697368,"lng" : -87.1909496
               },"southwest" : {
                  "lat" : 38.6799492,"lng" : -87.2229644
               }
            }
         },"place_id" : "ChIJ0e364hPebYgRigmh1xFd6TI",{
         "address_components" : [
            {
               "long_name" : "Palestine","short_name" : "Palestine","types" : [ "neighborhood",{
               "long_name" : "Paris",{
               "long_name" : "Henry County","short_name" : "Henry County",{
               "long_name" : "Tennessee","short_name" : "TN",{
               "long_name" : "38242","short_name" : "38242","formatted_address" : "Palestine,Paris,TN 38242,"geometry" : {
            "location" : {
               "lat" : 36.2589479,"lng" : -88.40199149999999
            },"viewport" : {
               "northeast" : {
                  "lat" : 36.2679447,"lng" : -88.3859841
               },"southwest" : {
                  "lat" : 36.2499501,"lng" : -88.4179989
               }
            }
         },"place_id" : "ChIJ4wFtXAe-e4gRs1UnOjUUm1c",{
         "address_components" : [
            {
               "long_name" : "Texas","formatted_address" : "Texas,"geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 36.5007041,"lng" : -93.5080389
               },"southwest" : {
                  "lat" : 25.8371638,"lng" : -106.6456461
               }
            },"location" : {
               "lat" : 31.9685988,"lng" : -99.9018131
            },"viewport" : {
               "northeast" : {
                  "lat" : 36.5007041,"lng" : -106.6456461
               }
            }
         },"place_id" : "ChIJSTKCCzZwQIYRPN4IGI8c6xY",{
         "address_components" : [
            {
               "long_name" : "Monroe County","short_name" : "Monroe County","formatted_address" : "Monroe County,"geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 39.662932,"lng" : -91.711934
               },"southwest" : {
                  "lat" : 39.3373651,"lng" : -92.31004899999999
               }
            },"location" : {
               "lat" : 39.5508815,"lng" : -92.0665197
            },"viewport" : {
               "northeast" : {
                  "lat" : 39.662932,"lng" : -92.31004899999999
               }
            }
         },"place_id" : "ChIJOV2qxv0M3YcRAKucv30D33c","political" ]
      }
   ],"status" : "OK"
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-