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

Update the markers without refreshing the complete map. #344

Open
shahronak47 opened this issue Jan 31, 2023 · 0 comments
Open

Update the markers without refreshing the complete map. #344

shahronak47 opened this issue Jan 31, 2023 · 0 comments

Comments

@shahronak47
Copy link

shahronak47 commented Jan 31, 2023

I have an asset whose position is coming from a database that I am plotting on a map. Every few seconds I want to refresh its position to display its current position. While doing that the complete map gets refreshed showing a small blip for a split second. Is there a way I can avoid that?

Here is a reproducible example below where I am using Sys.sleep(5) to show an update from the database. Ideally, I would expect the point to be updated on the same map itself instead of refreshing the complete map. It becomes really annoying when the map gets updated 10 times in a minute.

library(dplyr)
library(ggmap)

d <- data.frame(lat=c(50.659631, 50.607213, 50.608129),
                lon=c(3.09319, 3.011473, 3.031529))

Lille <- get_map("Lille,France", zoom=12)

p <- ggmap(Lille)
p + geom_point(data=d, aes(x=lon, y=lat), color="red", size=10, alpha=0.5)
Sys.sleep(5)
#shift the points randomly slowly
d1 <- d %>% mutate(lat = lat + runif(n(), -0.01, 0.01), lon = lon + runif(n(), -0.01, 0.01))
p + geom_point(data=d1, aes(x=lon, y=lat), color="red", size=10, alpha=0.5)

I found a few examples on stack overflow but they don't have a concrete answer and none of them has an R answer so I don't know how to implement this.

https://stackoverflow.com/questions/8673111/how-to-update-google-map-pins-without-refreshing-the-whole-map
https://stackoverflow.com/questions/43906523/how-to-update-markers-on-google-map-without-refresh
https://stackoverflow.com/questions/40491947/how-to-update-location-without-refresh-google-map-using-javascript

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

1 participant