从R的Google Places API抓取地方的描述 [英] Grabbing a Place's description from Google Places API in R

查看:143
本文介绍了从R的Google Places API抓取地方的描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对可怜的截图事先道歉。查看下面的屏幕截图,我想要一种向Google Maps发送HTTP请求查询(用蓝色圈起来),选择建议的搜索词(如果可用)以及以JSON格式返回第一个结果的方法。从那里,我想解析出这个地方的描述。这在屏幕截图中以红色圈出。我搜索了Google Maps和Places API,但找不到足够的部分来实现解决方案。编辑:这不适用于实际生产使用。这是我想通过发送用户输入名称的CSV列表来使用的一次性解决方案。



对此非常感激。

使用Google Places API您可能不会使用Google Places API能够得到你的描述(你的红圈)。



这是一个解决方案,使用我的 googleway 包(它为你解析JSON)

$ p $ lt; code> library(googleway)

apiKey< - ' your_api_key'

myPlace< - google_places(search_string =ebm-papst Inc,key = apiKey)
myPlace
#$ results
#formatted_address geometry.location .lat geometry.location.lng geometry.viewport.northeast.lat
#1 100 Hyde Rd,Farmington,CT 06032,United States 41.69905 -72.86462 41.69995
#geometry.viewport.northeast.lng geometry.viewport .southwest.lat geometry.viewport.southwest.lng
#1 -72.86326 41.69726 -72.86595
#图标ID名称
#1 https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png 0bad18aa7e39cb7cbbaea097994f4cf258a8c9f2 ebm-papst Inc.
照片#
#1 2848,< A HREF = https://maps.google.com/maps/contrib/116194079529080031684/photos > ebmpapstUSA< / A>中CmRYAAAApkJrPj2Esm7Zj3JbYi4GGq4n2_HKa8lD4ajJEiJqreY7g-fqeybxAdN_Y3i12YR7CtlwpzVLOgfGYlKr_dq7lcHywOxFTZ71w5fLAnCwCcckwpwnSN5-ZFHyxatfKDWtEhAiqZ_cUZYZG86txisUiQJuGhSxfmgURHQQsMGrcoCpc_nbthsUnw,4272
#place_id评级
#1 ChIJk4hBjUWw54kRQ3xwJR2K93g 5
#参考
#1 CmRRAAAAi5th813z3Vidbe399oEgJx0QtweOq395pxBZQIpcNVUUieJPvxOh7_5CiQDY2mzPtoeiN8URmpRWKFLu7OzemOjgFiH3PUT8al7KQGsVF-4uHVL_fMffeF77QzagdsBDEhDEOxx5M5f5c4gvrPFbq3LoGhTnlkNSFopZ2CjGKzl2XrTOIvkz6A
#类型
#1 point_of_interest,建立

您可以然后使用 place_id 字段获取有关特定位置的更多详细信息。然而,我无法看到它在任何地方说'制造商'

  myPlaceId<  -  myPlace $ results [1,] $ place_id 

google_place_details(place_id = myPlaceId,key = apiKey)
#$ result
#$ result $ address_components
#long_name short_name types
#1 100 100 street_number
#2海德路海德路线
#3法明顿法明顿地方政治
#4哈特福德县哈特福德县administrative_area_level_2,政治
#5康涅狄格州CT administrative_area_level_1,政治
#6美国美国国家政治
#7 06032 06032邮政编码
#8 2835 2835邮政编码_suffix

#$结果$ adr_address $ b < span class = \locality \> Farmington< / span> ,< span class = \\region \\> CT< / span> < span class = \postal-code \> 06032-2835< / span>,< span class = \country-name \>美国< / span>

#$ result $ formatted_address
#[1]100 Hyde Rd,Farmington,CT 06032,USA

#$ result $ formatted_phone_number
#[ 1](860)674-1515

#$ result $ geometry
#$ result $ geometry $ location
#$ result $ geometry $ location $ lat
#[1] 41.69905

#$ result $ geometry $ location $ lng
#[1] -72.86462


# $ result $ geometry $ viewport
#$ result $ geometry $ viewport $ northeast
#$ result $ geometry $ viewport $ northeast $ lat
#[1] 41.69995

#$ result $ geometry $ viewport $ northeast $ lng
#[1] -72.86326


#$ result $ geometry $ viewport $ southwest
#$ result $ geometry $ viewport $ southwest $ lat
#[1] 41.69726

#$ result $ geometry $ viewport $ southwest $ lng
#[1] -72.86595

#$ result $ icon
#[1]https://maps.gstatic.com/mapfiles/pl ace_api / icons / generic_business-71.png

#$ result $ id
#[1]0bad18aa7e39cb7cbbaea097994f4cf258a8c9f2

#$ result $ international_phone_number $
#[1]+1 860-674-1515

#$ result $ name
#[1]ebm-papst Inc.

#$ result $ photos
#height html_attributions
#1 2848< a href =https://maps.google.com/maps/contrib/116194079529080031684/photos> ebmpapstUSA< ; / A>
#photo_reference
#1 CmRYAAAAncznMEY_qxszVm2aRsutCo2h_aFJPnQuRetv-qUdo6Z66UCQII6iIEkSXB81k__Ys_earablgBtRq2yFObg0_Ul2xiigSX-fOHiBwrzhKBI4Axz_m72m8u2EVQ3o5lNPEhDGJiqQlUscKYhNCw4a-w4xGhQKhdR8TaZXft29PlD99hWVt62EBA
#宽度
#1 4272

#$结果$ place_id
#[1]ChIJk4hBjUWw54kRQ3xwJR2K93g

#$ result $ rating
#[1] 5

#$ result $ reference
#[ 1] CmRRAAAAU9Pt8Bh8VMqqdQ6PRUVxK9X-h6rma8y9BSiqmk4rVcuFPDzJpuX4bdmjLxNhRoOrEDLOKT4CFzNCwT1UXnxl_ezNenzachDjezWp9sGtgt8k5XUjXyF3W_x4ZZJEtqqOEhARfYhWNHUV_gCVTwfpG5OhGhT2pu-L1dTJBho2ekzaO _-_ 06C-0瓦特

$#$结果评论
#AUTHOR_NAME author_url语言
#1大卫·奎斯塔https://www.google .com / maps / contrib / 117339667056469092013 /评论es
#profile_photo_url评级
#1 https://lh5.googleusercontent.com/--1xFme4FMZk/AAAAAAAAAAI/AAAAAAAAAA4/apolINU9s78/s128-c0x00000000-cc- rp-mo / photo.jpg 5
#relative_time_description text time
#1 9 months ago 1471529234

#$ result $ scope
#[1]GOOGLE

#$结果$ types
#[1]point_of_interestestablishment

#$ result $ url
#[1]https://maps.google.com/ ?cid = 8716587461585697859

#$ result $ utc_offset
#[1] -240

#$ result $ Nearby
#[1 ]100 Hyde Road,Farmington

#$ result $ website
#[1]http://www.ebmpapst.us/


My apologies in advance for the poor screenshot. Looking at the screenshot below, I want to have a way of sending an HTTP request query to Google Maps (circled in blue), selecting the suggested search term (if available), and returning the first result in JSON format. From there, I want to parse out the place's description. This is circled in red in the screenshot. I've scoured the Google Maps and Places API but could not find enough pieces to implement a solution.

EDIT: This wouldn't be for live production use. It's a one-time solution I want to use by sending a CSV list of user-entered names.

Any assistance with this is greatly appreciated.

解决方案

Using the Google Places API you may not be able to get the description (your red circle) that you're after.

Here's a solution using my googleway package (which parses the JSON for you)

library(googleway)

apiKey <- 'your_api_key'

myPlace <- google_places(search_string = "ebm-papst Inc", key = apiKey)
myPlace
# $results
# formatted_address geometry.location.lat geometry.location.lng geometry.viewport.northeast.lat
# 1 100 Hyde Rd, Farmington, CT 06032, United States              41.69905             -72.86462                        41.69995
# geometry.viewport.northeast.lng geometry.viewport.southwest.lat geometry.viewport.southwest.lng
# 1                       -72.86326                        41.69726                       -72.86595
# icon                                       id           name
# 1 https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png 0bad18aa7e39cb7cbbaea097994f4cf258a8c9f2 ebm-papst Inc.
# photos
# 1 2848, <a href="https://maps.google.com/maps/contrib/116194079529080031684/photos">ebmpapstUSA</a>, CmRYAAAApkJrPj2Esm7Zj3JbYi4GGq4n2_HKa8lD4ajJEiJqreY7g-fqeybxAdN_Y3i12YR7CtlwpzVLOgfGYlKr_dq7lcHywOxFTZ71w5fLAnCwCcckwpwnSN5-ZFHyxatfKDWtEhAiqZ_cUZYZG86txisUiQJuGhSxfmgURHQQsMGrcoCpc_nbthsUnw, 4272
# place_id rating
# 1 ChIJk4hBjUWw54kRQ3xwJR2K93g      5
# reference
# 1 CmRRAAAAi5th813z3Vidbe399oEgJx0QtweOq395pxBZQIpcNVUUieJPvxOh7_5CiQDY2mzPtoeiN8URmpRWKFLu7OzemOjgFiH3PUT8al7KQGsVF-4uHVL_fMffeF77QzagdsBDEhDEOxx5M5f5c4gvrPFbq3LoGhTnlkNSFopZ2CjGKzl2XrTOIvkz6A
# types
# 1 point_of_interest, establishment

You can then use the place_id field to get further details about a specific place. However, I can't see it saying 'manufacturer' anywhere

myPlaceId <- myPlace$results[1, ]$place_id

google_place_details(place_id = myPlaceId, key = apiKey)
# $result
# $result$address_components
# long_name      short_name                                  types
# 1             100             100                          street_number
# 2       Hyde Road         Hyde Rd                                  route
# 3      Farmington      Farmington                    locality, political
# 4 Hartford County Hartford County administrative_area_level_2, political
# 5     Connecticut              CT administrative_area_level_1, political
# 6   United States              US                     country, political
# 7           06032           06032                            postal_code
# 8            2835            2835                     postal_code_suffix
# 
# $result$adr_address
# [1] "<span class=\"street-address\">100 Hyde Rd</span>, <span class=\"locality\">Farmington</span>, <span class=\"region\">CT</span> <span class=\"postal-code\">06032-2835</span>, <span class=\"country-name\">USA</span>"
# 
# $result$formatted_address
# [1] "100 Hyde Rd, Farmington, CT 06032, USA"
# 
# $result$formatted_phone_number
# [1] "(860) 674-1515"
# 
# $result$geometry
# $result$geometry$location
# $result$geometry$location$lat
# [1] 41.69905
# 
# $result$geometry$location$lng
# [1] -72.86462
# 
# 
# $result$geometry$viewport
# $result$geometry$viewport$northeast
# $result$geometry$viewport$northeast$lat
# [1] 41.69995
# 
# $result$geometry$viewport$northeast$lng
# [1] -72.86326
# 
# 
# $result$geometry$viewport$southwest
# $result$geometry$viewport$southwest$lat
# [1] 41.69726
# 
# $result$geometry$viewport$southwest$lng
# [1] -72.86595
# 
# $result$icon
# [1] "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png"
# 
# $result$id
# [1] "0bad18aa7e39cb7cbbaea097994f4cf258a8c9f2"
# 
# $result$international_phone_number
# [1] "+1 860-674-1515"
# 
# $result$name
# [1] "ebm-papst Inc."
# 
# $result$photos
# height                                                                           html_attributions
# 1   2848 <a href="https://maps.google.com/maps/contrib/116194079529080031684/photos">ebmpapstUSA</a>
#   photo_reference
# 1 CmRYAAAAncznMEY_qxszVm2aRsutCo2h_aFJPnQuRetv-qUdo6Z66UCQII6iIEkSXB81k__Ys_earablgBtRq2yFObg0_Ul2xiigSX-fOHiBwrzhKBI4Axz_m72m8u2EVQ3o5lNPEhDGJiqQlUscKYhNCw4a-w4xGhQKhdR8TaZXft29PlD99hWVt62EBA
# width
# 1  4272
# 
# $result$place_id
# [1] "ChIJk4hBjUWw54kRQ3xwJR2K93g"
# 
# $result$rating
# [1] 5
# 
# $result$reference
# [1] "CmRRAAAAU9Pt8Bh8VMqqdQ6PRUVxK9X-h6rma8y9BSiqmk4rVcuFPDzJpuX4bdmjLxNhRoOrEDLOKT4CFzNCwT1UXnxl_ezNenzachDjezWp9sGtgt8k5XUjXyF3W_x4ZZJEtqqOEhARfYhWNHUV_gCVTwfpG5OhGhT2pu-L1dTJBho2ekzaO_-_06C-0w"
# 
# $result$reviews
# author_name                                                        author_url language
# 1 David Cuesta https://www.google.com/maps/contrib/117339667056469092013/reviews       es
# profile_photo_url rating
# 1 https://lh5.googleusercontent.com/--1xFme4FMZk/AAAAAAAAAAI/AAAAAAAAAA4/apolINU9s78/s128-c0x00000000-cc-rp-mo/photo.jpg      5
# relative_time_description text       time
# 1              9 months ago      1471529234
# 
# $result$scope
# [1] "GOOGLE"
# 
# $result$types
# [1] "point_of_interest" "establishment"    
# 
# $result$url
# [1] "https://maps.google.com/?cid=8716587461585697859"
# 
# $result$utc_offset
# [1] -240
# 
# $result$vicinity
# [1] "100 Hyde Road, Farmington"
# 
# $result$website
# [1] "http://www.ebmpapst.us/"

这篇关于从R的Google Places API抓取地方的描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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