Automatically open both Google Map and Streetview

ぐ巨炮叔叔 提交于 2019-12-06 13:37:34

问题


I'm wondering if someone better than I am at R Shiny could tell me if the following is possible (it may not be, but I'd like to know if not).

Question: Can I open both a google map and interactive streetview in Shiny?

Why I want to do this:

I have a programmed google map coming from the googleway package shiny integration. It looks as below (code at the bottom):

In my shiny app, I can click and drag the streetview guy in the from the icon in the corner:

Resulting in the streetview:

I'd like to jump straight into this street view on an action button or tab click instead of making the user do the drag and drop process, so that I can have the map in one shiny tab and directly into the interactive streetview in another tab, or better yet have the map and streetview side by side as in (link here: https://developers.google.com/maps/documentation/javascript/examples/streetview-simple).

Is there a way to do this?

I am also looking into googleway package to see if there is another way, but as far as I can tell I can get into an interactive panorama but not street view directly. I am also looking into the possibility of using the html integration in shiny to go directly into Street View service.

Code (simplified, but tested):

library(googleway)
library(shiny)

gpscoordlat <- 39.647806
gpscoordlon <- -104.940230
markerpointsplace <- data.frame(
  lat=c(gpscoordlat),
  lon=c(gpscoordlon)
)

ui <- fluidPage(google_mapOutput("map"))


server <- function(input, output, session){

 ###Use Your API key here###
  api_key <- "GoogleAPIKeyHere"


  output$map <- renderGoogle_map({
    google_map(location=c(gpscoordlat, gpscoordlon), key= api_key, zoom=15) %>%
      add_markers(data=markerpointsplace , update_map_view= FALSE)

  })
}
shinyApp(ui, server)

回答1:


Caution

This functionality is currently under development. Progress can be tracked directly on github, but I will endeavour to update this post as I go along.

You can install the development version using

devtools::install_github("SymbolixAU/googleway")

Example

Here's an example of two maps, both controlled by the same street-view 'pegman'.

Note the two UI outputs, the standard map output, and another one I've called pano. This pano is then used in the split_view argument to google_map()

library(shiny)
library(shinydashboard)
library(googleway)

ui <- dashboardPage(

  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    box(width = 6,
      google_mapOutput(outputId = "map")
    ),
    box(width = 6,
        google_mapOutput(outputId = "pano")
    )
  )
)

server <- function(input, output) {
  set_key("map_api_key")

  output$map <- renderGoogle_map({
    google_map(location = c(-37.817386, 144.967463), 
             zoom = 12, 
             split_view = "pano")
  })
}

shinyApp(ui, server)

Notes

  • if your initial location doesn't fall directly on a valid 'street view' location, the streetview page will be blank


来源:https://stackoverflow.com/questions/48898469/automatically-open-both-google-map-and-streetview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!