当前位置:网站首页>Baidu map - surrounding search
Baidu map - surrounding search
2022-07-03 02:31:00 【Python's path to immortality】
brief introduction
Today we'll learn a more interesting Map api
LocalSearch
. Through it, we can search the surrounding addresses on the map , You can also search the address within the specified range .
LocalSearch
- Belong to
Map api
The service class , Mainly used for location retrieval 、 Perimeter search and scope search . - The parameter type can be a map instance 、 A string of coordinate points or city names .
- When the parameter is a map instance , The retrieval position is determined by the current map center point , And the labels of the search results will be automatically loaded on the map , It also supports adjusting the view level of the map ; When the parameter is coordinate , The retrieval location is determined by the location of the point ; When the parameter is city name , The search will be conducted in the city .
- Detailed documentation
Keyword search
search()
Initiate a search based on the search term , When you pass in an array, you can perform multi keyword retrieval .
var local = new BMapGL.LocalSearch(map, {
renderOptions: {
map: map }
})
local.search(' The hospital ')
- You're right
Map api
Powerful function, just a few lines of code to complete the retrieval .
Get retrieval data
- In addition to displaying labels on the map , We also need to get the retrieved data for other operations .
LocalSearch()
Second argument to constructorLocalSearchOptions
, It is used to obtain the retrieved data .
renderOptions
Automatic generationDOM
The text list block shows .onSearchComplete
Callback function after retrieval . Get the retrieved data here .
...
// Secret renderOptions Elements used
<div id="r-result"></div>
...
var myKeys = [' The hotel ', ' The hospital ']
var local = new BMapGL.LocalSearch(map, {
renderOptions: {
map: map, panel: 'r-result' },
onSearchComplete: function (res) {
console.log(' ~ file: Map perimeter retrieval .html ~ line 33 ~ res', res)
}
})
local.search(myKeys)
Search by region
- When the search scope is too large, there may be no results or slow response , At this time, the control range is needed .
searchInBounds()
Initiate a scope search based on the scope and search term , Passing in an array can perform multi keyword retrieval .BMapGL.Bounds()
Create a rectangular area of geographic coordinates .
var local = new BMapGL.LocalSearch(map, {
renderOptions: {
map: map }
})
var pStart = new BMapGL.Point(121.480509, 31.23592)
var pEnd = new BMapGL.Point(126.480509, 36.23592)
// Set your own scope
var bs = new BMapGL.Bounds(pStart, pEnd)
local.searchInBounds(' The hospital ', bs)
- In addition to the inner rectangle, of course, there are also circular search methods .
searchNearby()
According to the center point 、 Radius and search term initiate peripheral search . Passing in an array can perform multi keyword retrieval .- Note that the unit of radius here is rice
var local = new BMapGL.LocalSearch(map, {
renderOptions: {
map: map, autoViewport: false }
})
local.searchNearby(' The hospital ', new BMapGL.Point(121.480509, 31.23592), 1000)
Retrieve data control
- The retrieved data is not all returned at once , Is returned by paging . In this way, we can control how much data is displayed in a range , To ensure the user experience .
setPageCapacity()
Set how many pieces of data are displayed on a page .gotoPage()
Jump to the specified page .
// Total number of pages
var pageAll = 0
var myKeys = [' The hotel ', ' The hospital ']
var local = new BMapGL.LocalSearch(map, {
renderOptions: {
map: map, panel: 'r-result' },
onSearchComplete: function (res) {
console.log(' ~ file: Map perimeter retrieval .html ~ line 35 ~ res', res)
pageAll = res[0].getNumPages()
}
})
local.setPageCapacity(20)
local.search(myKeys)
var i = 0 // the number of pages
function onBut() {
if (i === pageAll) {
i = 0
} else {
i++
}
local.gotoPage(i)
}
边栏推荐
- Gbase 8C trigger (II)
- Startup mode and scope builder of collaboration in kotlin
- 为什么会选择框架?选择什么样的框架
- Awk from getting started to getting into the ground (3) the built-in functions printf and print of awk realize formatted printing
- [shutter] banner carousel component (shutter_wiper plug-in | swiper component)
- RestCloud ETL 跨库数据聚合运算
- Gbase 8C function / stored procedure definition
- [codeforces] cf1338a - Powered addition [binary]
- Principle and application of database
- Unrecognized SSL message, plaintext connection?
猜你喜欢
[Flutter] dart: class;abstract class;factory;类、抽象类、工厂构造函数
【翻译】后台项目加入了CNCF孵化器
Detailed analysis of micro service component sentinel (hystrix)
[shutter] setup of shutter development environment (supplement the latest information | the latest installation tutorial on August 25, 2021)
[translation] the background project has joined the CNCF incubator
What does "where 1=1" mean
udp接收队列以及多次初始化的测试
通达OA v12流程中心
Error invalid bound statement (not found): com ruoyi. stock. mapper. StockDetailMapper. XXXX solution
Detailed introduction to the deployment and usage of the Nacos registry
随机推荐
Gbase 8C system table PG_ database
Cancellation of collaboration in kotlin, side effects of cancellation and overtime tasks
[shutter] setup of shutter development environment (supplement the latest information | the latest installation tutorial on August 25, 2021)
Unrecognized SSL message, plaintext connection?
QT qcombobox add qccheckbox (drop-down list box insert check box, including source code + comments)
Why choose a frame? What frame to choose
udp接收队列以及多次初始化的测试
Simple understanding of SVG
GBase 8c触发器(二)
easyExcel
[translation] flux is safe. Gain more confidence through fuzzy processing
怎么将yolov5中的PANet层改为BiFPN
HW-初始准备
Apple releases MacOS 11.6.4 update: mainly security fixes
面试八股文整理版
Gbase 8C system table PG_ conversion
Recommendation letter of "listing situation" -- courage is the most valuable
Random shuffle note
Build a private cloud disk cloudrev
5.文件操作