I am interested in plotting the route from Waterloo to Taiwan using the leaflet library for R. The coordinates for the route was obtained using gcIntermediate function from geosphere. However, the route involves the crossing of the international dateline and hence the route gets cut-off at the edges of the map and is joined at the top with a straight line.
Plot that I get: wrong map
Plot that I want: ideal map
There is a possibility that this problem could be solved using Google maps but is there a way to solve this using leaflet? How should I modify the code below to get the ideal route? Thank you!
Code:
library(dplyr)
library(leaflet)
library(geosphere)
# Source
latWaterloo <- 43.46687
lngWaterloo <- -80.52464
# Destination
latTaiwan <- 23.5983
lngTaiwan <- 120.8354
m <- leaflet() %>% addTiles()
m <- addCircleMarkers(m, lng=c(lngWaterloo, lngTaiwan) , lat=c(latWaterloo, latTaiwan), popup=c("Waterloo","Taiwan"), radius=5, opacity=0.5)
geo_lines <- gcIntermediate(c(lngWaterloo, latWaterloo), c(lngTaiwan, latTaiwan), n=100, addStartEnd=T, sp=T, breakAtDateLine=F)
m <- addPolylines(m, data=geo_lines, color="blue")
m
m <- leaflet() %>% addTiles()
m