在传单中找到两个标记之间的中间点

Find the middle point between two markers in Leaflet

我希望能够找到地图上两个标记之间的中心点(如下例)。 leaflet 或其他包中是否有允许这样做的函数?提前谢谢你

coor_zone6 <- c(3.16680, 3.16176, 42.46667, 42.46997)
matrice_coord_zone6 <- matrix(coor_zone6, nrow=2, ncol = 2)
colnames(matrice_coord_zone6) <- c("long", "lat")
matrice_coord_zone6 <- data.frame(matrice_coord_zone6)
matrice_coord_zone6$name <- c("M_1","M_3")

leaflet(matrice_coord_zone6) %>%
  addMouseCoordinates(epsg = NULL, proj4string = NULL, native.crs = FALSE) %>%
  addProviderTiles("Esri.WorldImagery") %>%
  addMarkers(lng = ~long, lat = ~lat) %>%
  addPolylines(~long, ~lat, popup = ~name)

我还没有找到任何可以执行此计算的传单函数,但不难找到两个坐标之间的中间点。

您必须添加两个经度并将它们除以 2,您必须对两个纬度执行相同的操作。

你的情况,如果我没看错的话,你的第一个坐标是(3.16680, 42.46667),第二个坐标是(3.16176, 42.46997),所以计算如下:

(3,16680 + 3,16176) / 2 = 3,16428
(42,46667 + 42,46997) / 2 = 42,46832

所以中间点如下:(3.16428, 42.46832)