OpenLayers加载高德地图(谷歌暂时访问不了,那就访问国内地图吧,速度更快)

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>OpenLayers加载高德地图</title>
<link rel="stylesheet" href="theme/default/style.css" type="text/css">
<script src="lib/OpenLayers.js"></script>
<script type="text/javascript">
var map, layer,marker;
var layerOptions=null;

function init(){
//map = new OpenLayers.Map('map');
map = new OpenLayers.Map({
 div: "map",
 projection: "EPSG:900913",  //指定投影很关键
 displayProjection: new OpenLayers.Projection("EPSG:4326")});

var gdLayer = new OpenLayers.Layer.XYZ("高德地图", [ 
                      "http://webrd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x=${x}&y=${y}&z=${z}", 
                       "http://webrd02.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x=${x}&y=${y}&z=${z}", 
                        "http://webrd03.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x=${x}&y=${y}&z=${z}", 
                        "http://webrd04.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x=${x}&y=${y}&z=${z}" 
        ], { 
            isBaseLayer: true, 
            visibility: true, 
            displayInLayerSwitcher: true 
        }); 
map.addLayer(gdLayer);
map.addControl(new OpenLayers.Control.LayerSwitcher());
var lonlat=new OpenLayers.LonLat(102.70734, 25.04505);
  alert( map.getProjectionObject()); //当前是EPSG:900913投影
var lonlat2 = lonlat.clone().transform( new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject() );//转换投影
map.setCenter(lonlat2, 8);//指定地图中心与初始缩放级别
map.addControl(new OpenLayers.Control.MousePosition());
}
</script>
<body οnlοad="init()">
<div id="map" style="position:relative;width: 80%;height: 80%;border: 1px solid #ccc;">
</div>
</body>
</html>
/*致谢
*To修哥的博客http://blog.csdn.net/devcopper
*/

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值