高德地图搜索框提示demo效果(整理)

在这里插入图片描述

<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
		<title>输入提示后查询</title>
		<link rel="stylesheet" href="https://cache.amap.com/lbs/static/main1119.css" />
	</head>
	<body>
		<div id="container"></div>
		<div id="seekBox">
			<table>
				<tr>
					<td>
						<label>请输入关键字:</label>
					</td>
				</tr>
				<tr>
					<td>
						<input id="hintPut" />
					</td>
				</tr>
			</table>
		</div>
		<script type="text/javascript">
			window._AMapSecurityConfig = {
    
    
				securityJsCode: 'be00dfb4bcd4b18dd7760486c40aa1ed', //秘钥
			}
		</script>
		<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=c4f7071b37d26db04796152dca559ec4">
		</script>
		<script type="text/javascript">
			//地图加载
			var map = new AMap.Map("container", {
    
    
				resizeEnable: true, //是否监控地图容器尺寸变化
				zoom: 16, //初始化地图层级
				// center: [116.397428, 39.90923] //初始化地图中心点
			});
			//输入提示
			var autoOptions = {
    
    
				input: "hintPut"
			};

			AMap.plugin(['AMap.PlaceSearch', 'AMap.Autocomplete'], function() {
    
    
				var auto = new AMap.Autocomplete(autoOptions);
				var placeSearch = new AMap.PlaceSearch({
    
    
					map: map
				}); //构造地点查询类
				auto.on("select", select); //注册监听,当选中某条记录时会触发
				function select(e) {
    
    
					placeSearch.setCity(e.poi.adcode);
					placeSearch.search(e.poi.name); //关键字查询查询
				}
			});
		</script>
	</body>
</html>

猜你喜欢

转载自blog.csdn.net/qq_38881495/article/details/127688937
今日推荐