Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geolocation #173

Closed
SymbolixAU opened this issue Aug 11, 2018 · 7 comments
Closed

Geolocation #173

SymbolixAU opened this issue Aug 11, 2018 · 7 comments
Milestone

Comments

@SymbolixAU
Copy link
Collaborator

https://developers.google.com/maps/documentation/javascript/geolocation

@SymbolixAU SymbolixAU self-assigned this Aug 11, 2018
@SymbolixAU SymbolixAU added this to the 2.7 milestone Aug 11, 2018
SymbolixAU pushed a commit that referenced this issue Aug 12, 2018
@SymbolixAU
Copy link
Collaborator Author

To observe a user's location

observeEvent({ input$map_id_geolocation }, { } )

@SymbolixAU SymbolixAU modified the milestones: 2.7, 2.8 Aug 31, 2018
@tnelsen
Copy link

tnelsen commented Dec 17, 2020

I am not able to access the geolocation in this way. I am getting "geolocation.js:23 Uncaught ReferenceError: map_id is not defined at geolocation.js:23" in my browser developer tools. A minimal example is below. I can print from map click, marker drag, etc. but am getting NULL if I try to return the geolocation. Thanks in advance.

library(googleway)
library(shiny)

readRenviron('../.Renviron')

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

server <- function(input, output, session){
	output$map <- renderGoogle_map({
		google_map(key = Sys.getenv("MAPS_API_KEY"), location = c(38.54, -121.78),
							 zoom = 8, search_box = TRUE, geolocation = TRUE,
							 width = '100%', height = '100%'
		) %>%
			add_markers(data = data.frame(lat = 38.54, lon = -121.78),
									draggable = TRUE, update_map_view = FALSE)})
	
	observeEvent(input$map_marker_drag, {
		print(input$map_marker_drag)
	})
	
	observeEvent(input$map_map_click, {
		print(input$map_map_click)
	})
	
	#https://github.com/SymbolixAU/googleway/issues/173
	observeEvent(input$map_geolocation,{
		print(input$map_geolocation)
	})
}

shinyApp(ui, server)

@dcooley
Copy link
Collaborator

dcooley commented Dec 17, 2020

Are you opening this in a browswer, and do you have it set to "allow location" ?

@tnelsen
Copy link

tnelsen commented Dec 17, 2020

I am opening it in a Google Chrome browser and I get a pop-up asking if I want to allow it to access my location. I click yes but still nothing happens.

@dcooley
Copy link
Collaborator

dcooley commented Dec 17, 2020

oh I see, it might need a 'wait until map is ready' before calling the add_geolocation()... I'll look into it.

@dcooley dcooley reopened this Dec 17, 2020
@dcooley
Copy link
Collaborator

dcooley commented Dec 17, 2020

Ok this is not quite as straight forward, and I don't know if this worked before, but it's certainly not working now.

The add_geolocation() function in js needs to

  • 'observe' the geolocation result
  • send back to shiny server

It's working in the browser, but in shiny the 'position' object is empty...

$position
named list()

$randomValue
[1] 0.1187743

Ok it's working now

shinyApp(ui, server)

Listening on http://127.0.0.1:5590
$lat
[1] -37

$lon
[1] 144

$accuracy
[1] 20

$altitude
NULL

$altitudeAccuracy
NULL

$heading
NULL

$speed
NULL

$timestamp
[1] 1.608248e+12

$randomValue
[1] 0.9922257

@tnelsen
Copy link

tnelsen commented Dec 18, 2020

Thanks for this fix! It seems to be working now.

@dcooley dcooley closed this as completed Dec 18, 2020
@SymbolixAU SymbolixAU removed their assignment Jan 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants