Home > Back-end >  any good library to search on the basis of long and latitude?
any good library to search on the basis of long and latitude?

Time:08-09

I have a requirement where I have some cities' longitude and latitude.

Bangalore - 12.9539974,77.6309395
Chennai - 13.0473748,79.9288083
Delhi - 28.6921165,76.8079346
Mumbai - 19.0821978,72.741098

I have created an input box that has some cities listed down

Image

Based on this input I need to zoom into these cities.

How can I do this?

CodePudding user response:

Well, you can use a simple API for pinning out the location on selection. There are several API's available on net. The one I would suggest is to use a free API's like - IPAPI. All you need to do is to go through the documentation on their official website, in-order to get a close picture of how the API works.

CodePudding user response:

In that case, you can use a package 'ggmap' and its function named qmap() within it. or you can also check for package named 'maps'. Install this package and use map.cities() function.

There's one more lib for the same, its called rMaps. This package is available on github.

CodePudding user response:

I think there are a lot of ways to implement this, maybe it should work somehow. In any case, it is necessary to read the documentation.

HTML:   <div id="buttons"></div>

JS:
var Balganore = L.map('Bangalore').setView([12.9539974,77.6309395], 8);

Jquery:
 $('#buttons').append(
        $('<div>').text('City choose:'),
        $('<label>').append(
            $('<input>').prop({'type':'checkbox', 'checked':true}).click(function(){
                $(Bangalore).toggle();
    
            }),
            'Bangalore'
        ),)
   

CodePudding user response:

You can do this with leaflet

library(dplyr)
library(shiny)
library(leaflet)

data_cities = data.frame(
  city = c('Bangalore', 'Chennai', 'Delhi', 'Mumbai'),
  lat = c(12.9539974, 13.0473748, 28.6921165, 19.0821978),
  lng = c(77.6309395, 79.9288083, 76.8079346, 72.741098)
)

ui <- fluidPage(
  selectInput("select_city", label = "Select city", choices = data_cities$city),
  leafletOutput("map")
)

server <- function(input, output) {
  # Initiate the map
  output$map <- renderLeaflet({
    leaflet() %>% 
      addTiles(options = providerTileOptions(noWrap = TRUE)) 
  })
  
  #Zoom when select city
  observeEvent(input$select_city, {
    selected_city_data <- data_cities %>%
      filter(city == input$select_city)
    
    leafletProxy("map") %>%
      setView(lng = selected_city_data$lng, lat = selected_city_data$lat, zoom=8) 
    
  })
}
shinyApp(ui = ui, server = server)
  • Related