- Mark the locations of NTU Libraries
- Find out the nearest library
10/15/2018
(Note that I use random numbers to represent the user's choice) I created a dataframe with information of NTU libraries and the user's current location. Then I use leaflet to display the locations up to the user's choice.
Here, I construct a for loop to calculate the distance to every library from the user's location. Since the original data are in unit of degree, I transform the unit to meter by multiplying the factor (36788000/360)
i=1L
dist = data.frame(Library_Name = c("LWN","BUS","CHN"), Distance_to_Library=c(0,0,0))
points = data.frame(name = c("LWN","BUS","CHN","USER"),
lat = c(1.347488,1.346730,1.343671,input_userX),
lng = c(103.680936,103.679081,103.682313,input_userY),
popup = c("Lee Wee Nam Library","Business Library","Chinese Library","Current Location"),
size = c(5,5,5,10))
for (i in 1:3){
a = 36788000/360*sqrt((input_userX-points$lat[i])^2+(input_userY-points$lng[i])^2)
dist[i,2] = a
}
dist
## Library_Name Distance_to_Library ## 1 LWN 504.3989 ## 2 BUS 704.3814 ## 3 CHN 580.5719