如果对网址进行了编码,则对Google地理编码会返回不同的结果 [英] Google geo-coding returns different results if URL is encoded versus if it is not

查看:84
本文介绍了如果对网址进行了编码,则对Google地理编码会返回不同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

网址的结果 https://maps .googleapis.com/maps/api/geocode/json?address = 75019& sensor = false& components%3Dpostal_code:75019 |国家/地区:美国

两个url之间的唯一区别是,"components"之后的"="字符在第二个url中进行了编码.结果是第二个网址:我得到了2个结果,其中一个是Paris&一种是德克萨斯州的,这是不可取的.我想要仅针对国家(地区)=美国的结果.我们正在生产中使用第二个URL,但希望从第一个URL获得的结果.

The only difference between the two url's is that the "=" character after "components" is url encoded in the second url. As a result in second url: I get 2 results back, one for Paris & one for Texas, which is undesirable. I want results just for country = US. We are using the second url in production, but would like the results that we get from the first url.

问题是,即使过滤器明确提到该国为美国,我为什么也要从法国获得地址?

Issue is that even though the filter clearly mentions the country as US, why am I getting an address from France?

任何解决方案或见解?诊断正确吗?

Any solution or insights? Is the diagnosis correct?

推荐答案

不是在第二个URL中将国家指定为美国:

You're not specifying the country as US in the second URL:

第二个URL为google提供了一个名为"components%3Dpostal_code:75019 | country:US"的参数,没有内容,而第一个为google提供了一个名为"components"的参数,其内容为"postal_code:75019 | country:US" -=符号作为参数名称和值之间的分隔符非常重要.如果您对其进行url编码,则不再考虑将其用于此目的.

The second url gives google a parameter named "components%3Dpostal_code:75019|country:US" with no content, while the first one gives google a parameter named "components" with a content of "postal_code:75019|country:US" - the = sign is important as the separator between parameter name and value. If you url-encode it, it is not considered for this purpose anymore.

因此,如果它应该表示参数名与其值之间的分隔符,则不应对等号进行URL编码……这意味着您将不得不更改生产代码以产生第一个URL.第二个只是不代表您要表达的内容.

So, you should not URL-encode the equals sign if it should signify the separation between a parameter name and its value... meaning you will have to change your production code to produce the first URL. The second one just isn't representing what you want to express.

由于您不使用任何其他url编码字符(至少不在上面显示的链接中),因此在将请求发送给Google之前,也可以在某处进行单独的Url解码步骤(如果您绝对可以的话) 't更改生产代码).

Since you don't use any other url-encoded characters (at least not in the link shown above), it might also work to do a separate Url-decoding step somewhere before sending the request to google (if you absolutely can't change production code).

这篇关于如果对网址进行了编码,则对Google地理编码会返回不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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