Reputation: 157
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.
Upvotes: 0
Views: 790
Reputation: 26258
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/"
Upvotes: 4