百度地图API

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8" />

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>定点宾馆</title>

<link rel="stylesheet" href="css/jquery.mobile-1.4.2.css" type="text/css" media="screen" title="no title" charset="utf-8">

<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" title="no title" charset="utf-8">

<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=5aStOUxPdj151jB5wadV1M6x"></script>

<script type="text/javascript" charset="utf-8" src="js/jquery-2.0.2.js"></script>      

<script type="text/javascript" charset="utf-8" src="js/jquery.mobile-1.4.2.js"></script>

<script type="text/javascript" charset="utf-8" src="conf/moaconf.js"></script>

</head>

<body>

<div data-role="page">

<div data-role="header" data-position="fixed" id="header">

<a data-role="button" onclick="returnPrePage()" data-iconpos="notext" data-icon="back"></a>

<h1>定点宾馆</h1>

</div>

<div data-role="content">

<div id="map"></div>

</div>

</div>

</body>

</html>

<script type="text/javascript">

    $.mobile.loading("show");

    function returnPrePage(){

        window.history.go(-1);

    }

// 获取地址

var urlStr = location.href;

var paraString = urlStr.substring(urlStr.indexOf("?") + 1, urlStr.length).split("&");

var hotelIndex = paraString[0].split("=")[1];

var hotelObj = (jQuery.parseJSON(localStorage.hotellist))[hotelIndex];

var hotelName;

var address;

if("true" == localStorage.groupType || true == localStorage.groupType){

hotelName = hotelObj.hotelname;

address = hotelObj.hoteladress;

} else {

hotelName = hotelObj.tavernName;

address = hotelObj.tavernAddress;

}

// 设置map高度

var mapHeight = $(window).height() - $("#header").height();

$("#map").css("height", mapHeight);

// 百度地图API功能

var map = new BMap.Map("map");

map.addControl(new BMap.NavigationControl());

map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_TOP_RIGHT, type: BMAP_NAVIGATION_CONTROL_SMALL}));  

map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_BOTTOM_LEFT, type: BMAP_NAVIGATION_CONTROL_PAN}));  

map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_BOTTOM_RIGHT, type: BMAP_NAVIGATION_CONTROL_ZOOM}));  

var myGeo = new BMap.Geocoder();

myGeo.getPoint(address, function(point){

if(point){

map.centerAndZoom(point, 15);

map.addOverlay(new BMap.Marker(point));

var opts = {

width : 200,

height: 60,

title : hotelName,

enableMessage: false,

}

var infoWindow = new BMap.InfoWindow("地址:"+address, opts);

map.openInfoWindow(infoWindow,point);

            $.mobile.loading("hide");

} else {

cpicalert("百度地图无法定位到:"+address, "返回", returnPrePage);

}

});

</script>


你可能感兴趣的:(百度地图API)