从Google地图页面解析JSON响应

时间:2022-10-29 20:57:34

I'm trying to find the best way of parsing the response from a "normal" (i.e. not using the API) Google Maps page in my java code.

我正在尝试在我的java代码中找到解析来自“普通”(即不使用API​​)Google Maps页面的响应的最佳方法。

Reason: I want to submit a query string requesting a listing (be it hotels, restaurants etc.) and then parse the JSON that comes back. I had looked into using the Google Maps API, but it doesn't seem to cover what I want to do, as this type of URL:

原因:我想提交一个请求列表的查询字符串(无论是酒店,餐馆等),然后解析返回的JSON。我曾调查过使用Google Maps API,但它似乎没有涵盖我想要做的事情,因为这种类型的网址:

http://maps.google.de/maps/geo?q=address&output=xml&oe=utf8&sensor=false&key=...

is OK but this isn't:

没问题,但这不是:

http://maps.google.de/maps/geo?q=address+hotels&output=xml&oe=utf8&sensor=false&key=...

(due to the "+hotels" term). So I think the only option is to use a google maps response e.g.

(由于“+酒店”一词)。所以我认为唯一的选择是使用谷歌地图响应,例如

http://maps.google.de/maps?q=address+hotels

and parse the JSON information that is included at the end. Does anyone have some hints as to how best accomplish this?

并解析最后包含的JSON信息。有没有人有一些关于如何最好地完成这一点的提示?

2 个解决方案

#1


You should first make absolutely sure that the API doesn't support what you need. Checking the docs and maybe even reaching a real Googler might pay off. It strikes me as odd that their API wouldn't support something as simple as adding in another term.

您应首先确保API不支持您所需的内容。检查文档,甚至可能达到真正的Google员工可能会有所回报。令我感到奇怪的是,他们的API不支持像添加另一个术语那样简单的东西。

If you're forced to do it the "hard way", there are two main steps:

如果你*以“艰难的方式”去做,有两个主要步骤:

1) Find and learn a JSON parsing library for Java. I can recommend Jackson -- fast, sturdy, and just released a version 1.0.0.

1)查找并学习Java的JSON解析库。我可以推荐杰克逊 - 快速,坚固,刚刚发布了1.0.0版本。

2) Teach your code to understand the spec the Google uses in their response. This is by far the most challenging part. My apologies, but I know nothing about Google's spec in this area. If you can find official docs, that's best. Or find unofficial docs published by someone else who had to do similar work. Otherwise, you may have to "reverse engineer".

2)教您的代码,以了解Google在其回复中使用的规范。这是迄今为止最具挑战性的部分。我很抱歉,但我对谷歌在这方面的规格一无所知。如果你能找到官方文档,那就是最好的。或者找到必须做类似工作的其他人发布的非官方文档。否则,您可能需要“逆向工程”。

#2


Re. the google api docs: it does seem that what you're trying to do goes against the intention of Google to make their product (= a map) available to you, the developer, for your custom enhancement (by adding business outlet information or whatever). There's plenty of stuff on the Google maps API site describing this. But to parse their data (coming out of their database) and to display it independently of their product would seem to be rather different: section 10.12 of the terms explicitly cover this:

回覆。 google api docs:看起来你想要做的事情似乎违背了谷歌的意图,让你的开发者可以使用他们的产品(=地图)进行自定义增强(通过添加商业渠道信息或其他任何内容) )。 Google Maps API网站上有很多内容可以描述这一点。但是,解析他们的数据(从他们的数据库中出来)并独立于他们的产品显示它似乎是相当不同的:条款的第10.12节明确涵盖了这个:

...code.google.com/intl/de/apis/maps/terms.html

However, there are apps out there (the "Around Me" iPhone app, for example) that seem to do just that: there might be a special arrangement between Google and Apple in that regard.

但是,有些应用程序(例如“我身边的”iPhone应用程序)似乎就是这样:在这方面谷歌和苹果之间可能会有一个特殊的安排。

EDIT: alternatively you could look at this problem another way and use the Google Base API feed, since this allows you to build query strings specifying resource, distance, location etc. - i.e. it returns the data you require without using the Maps API (which you don't need anyway, given your description).

编辑:或者您可以通过另一种方式查看此问题并使用Google Base API供稿,因为这允许您构建指定资源,距离,位置等的查询字符串 - 即它返回您需要的数据而不使用Maps API(其中根据你的描述,你不需要。

#1


You should first make absolutely sure that the API doesn't support what you need. Checking the docs and maybe even reaching a real Googler might pay off. It strikes me as odd that their API wouldn't support something as simple as adding in another term.

您应首先确保API不支持您所需的内容。检查文档,甚至可能达到真正的Google员工可能会有所回报。令我感到奇怪的是,他们的API不支持像添加另一个术语那样简单的东西。

If you're forced to do it the "hard way", there are two main steps:

如果你*以“艰难的方式”去做,有两个主要步骤:

1) Find and learn a JSON parsing library for Java. I can recommend Jackson -- fast, sturdy, and just released a version 1.0.0.

1)查找并学习Java的JSON解析库。我可以推荐杰克逊 - 快速,坚固,刚刚发布了1.0.0版本。

2) Teach your code to understand the spec the Google uses in their response. This is by far the most challenging part. My apologies, but I know nothing about Google's spec in this area. If you can find official docs, that's best. Or find unofficial docs published by someone else who had to do similar work. Otherwise, you may have to "reverse engineer".

2)教您的代码,以了解Google在其回复中使用的规范。这是迄今为止最具挑战性的部分。我很抱歉,但我对谷歌在这方面的规格一无所知。如果你能找到官方文档,那就是最好的。或者找到必须做类似工作的其他人发布的非官方文档。否则,您可能需要“逆向工程”。

#2


Re. the google api docs: it does seem that what you're trying to do goes against the intention of Google to make their product (= a map) available to you, the developer, for your custom enhancement (by adding business outlet information or whatever). There's plenty of stuff on the Google maps API site describing this. But to parse their data (coming out of their database) and to display it independently of their product would seem to be rather different: section 10.12 of the terms explicitly cover this:

回覆。 google api docs:看起来你想要做的事情似乎违背了谷歌的意图,让你的开发者可以使用他们的产品(=地图)进行自定义增强(通过添加商业渠道信息或其他任何内容) )。 Google Maps API网站上有很多内容可以描述这一点。但是,解析他们的数据(从他们的数据库中出来)并独立于他们的产品显示它似乎是相当不同的:条款的第10.12节明确涵盖了这个:

...code.google.com/intl/de/apis/maps/terms.html

However, there are apps out there (the "Around Me" iPhone app, for example) that seem to do just that: there might be a special arrangement between Google and Apple in that regard.

但是,有些应用程序(例如“我身边的”iPhone应用程序)似乎就是这样:在这方面谷歌和苹果之间可能会有一个特殊的安排。

EDIT: alternatively you could look at this problem another way and use the Google Base API feed, since this allows you to build query strings specifying resource, distance, location etc. - i.e. it returns the data you require without using the Maps API (which you don't need anyway, given your description).

编辑:或者您可以通过另一种方式查看此问题并使用Google Base API供稿,因为这允许您构建指定资源,距离,位置等的查询字符串 - 即它返回您需要的数据而不使用Maps API(其中根据你的描述,你不需要。