当前位置:网站首页>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 apiLocalSearch. 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 apiThe 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 apiPowerful 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 .
renderOptionsAutomatic generationDOMThe text list block shows .onSearchCompleteCallback 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)
}

边栏推荐
- 《MATLAB 神经网络43个案例分析》:第43章 神经网络高效编程技巧——基于MATLAB R2012b新版本特性的探讨
- Word word word
- QT qcombobox add qccheckbox (drop-down list box insert check box, including source code + comments)
- GBase 8c系统表-pg_constraint
- awk从入门到入土(1)awk初次会面
- Detailed introduction to the deployment and usage of the Nacos registry
- GBase 8c系统表-pg_auth_members
- Javescript 0.1 + 0.2 = = 0.3 problem
- 机器学习流程与方法
- GBase 8c 触发器(一)
猜你喜欢

Producer consumer model based on thread pool (including blocking queue)

PyTorch 卷积网络正则化 DropBlock
![[shutter] banner carousel component (shutter_wiper plug-in | swiper component)](/img/a6/5c97ef3f34702b83ebf0511501d757.gif)
[shutter] banner carousel component (shutter_wiper plug-in | swiper component)
[advanced ROS] Lesson 6 recording and playback in ROS (rosbag)

Recommendation letter of "listing situation" -- courage is the most valuable

4. Classes and objects

SPI机制

Y54. Chapter III kubernetes from introduction to mastery -- ingress (27)

Random Shuffle attention

Create + register sub apps_ Define routes, global routes and sub routes
随机推荐
5.文件操作
Tongda OA V12 process center
Awk from introduction to earth (0) overview of awk
Summary of interview project technology stack
Apple releases MacOS 11.6.4 update: mainly security fixes
人脸识别6- face_recognition_py-基于OpenCV使用Haar级联与dlib库进行人脸检测及实时跟踪
GBase 8c系统表-pg_collation
[tutorial] chrome turns off cross domain policies CORS and samesite, and brings cookies across domains
[Flutter] dart: class; abstract class; factory; Class, abstract class, factory constructor
PyTorch 卷积网络正则化 DropBlock
[Hcia]No.15 Vlan间通信
Interview stereotyped version
[fluent] JSON model conversion (JSON serialization tool | JSON manual serialization | writing dart model classes according to JSON | online automatic conversion of dart classes according to JSON)
GBase 8c 触发器(一)
Servlet中数据传到JSP页面使用el表达式${}无法显示问题
GBase 8c系统表-pg_constraint
Su Shimin: 25 principles of work and life
Why choose a frame? What frame to choose
awk从入门到入土(2)认识awk内置变量和变量的使用
Apple releases MacOS 11.6.4 update: mainly security fixes