<html>
<head>
<meta http-equiv="Content-Type" content="text ml; charset=utf-8">
<title></title>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3" ></script>
</head>
<% String jd_id = request.getParameter("jd_id");%>
<% Dao dao = new DaoImpl(); %>
<%
List list = dao.executeQueryForList("SELECT NAME FROM S_LY_HOTEL_DATA WHERE id = "+jd_id+"");
java.util.Map map0 = (java.util.Map)list.get(0);
%>
<body>
<span id="map_id" style=display:none><%=map0.get("NAME") %></span>
<div style="position:absolute;width:730px;height:590px;top:50;left:0;border:1px solid gray;overflow-y:hidden;" id="container"></div>
</body>
<script>
var map = new BMap.Map("container");
var localSearch= new BMap.LocalSearch (map, {
renderOptions: {
pageCapacity: 8,
autoViewport: true,
selectFirstResult: false
}
});
function searchByStationName()
{
var jd_name=document.getElementById("map_id").innerText;
var keyword = jd_name;
localSearch.setSearchCompleteCallback(function(searchResult){
var poi = searchResult.getPoi(0);
map.enableScrollWheelZoom(); //启用地图滚轮放大缩小
map.enableDoubleClickZoom(); //启用鼠标双击放大,默认启用(可不写)
var point=new BMap.Point(poi.point.lng, poi.point.lat); //创建坐标点
map.centerAndZoom(point,19); //初始化地图,设置中心点坐标和地图级别
var marker=new BMap.Marker(point); //创建点覆盖物
map.addOverlay(marker);
map.centerAndZoom(poi.point, 19);
});
localSearch.search(keyword);
}
</script>
<script>
window.onload=function()
{
searchByStationName();
}
</script>
</html>
这是实现 通过 名称 确定 位置, 也能拿到 经纬度值, 具体 属性 去找百度API