使用百度地图增加自定义位置,如让会员商家在后台为自己的商铺标注坐标,前台显示,IE6也可以用。
记得把下面例子 http://api.map.baidu.com/api?v=1.5&ak=3E9F0128D0a3fadb4e3c7c8dd111ce1c 中的ak换成自己的key
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;}
#l-map{height:400px;width:400px;float:left;border-right:2px solid #bcbcbc;}
#r-result{height:100%;width:20%;float:left;}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.5&ak=3E9F0128D0a3fadb4e3c7c8dd111ce1c"></script>
<title>百度地图后台设置自定义坐标</title>
</head>
<body>
<div>
<div>
输入城市名:<input type="text" value="南平" id="city">
<input type="button" value="显示" οnclick="setCity()">
</div>
<div id="l-map"></div>
</div>
</body>
</html>
<script type="text/javascript">
//api实例 http://developer.baidu.com/map/jsdemo.htm#a1_2
//文档 http://developer.baidu.com/map/reference/index.php?title=Class:%E6%A0%B8%E5%BF%83%E7%B1%BB/Map
function setCity(){
var city_name = document.getElementById('city').value;
var map = new BMap.Map("l-map");
map.centerAndZoom(city_name,14);
setTimeout(function(){
var point = new BMap.Point(map.getCenter().lng,map.getCenter().lat);
var marker = new BMap.Marker(point); // 创建标注
map.addOverlay(marker); // 将标注添加到地图中
marker.enableDragging(); //可拖拽
//marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
var opts = {title : '<strong style="font-size:12px;">定位坐标:</strong>'}
var infoWindow = new BMap.InfoWindow('<span style="font-size:12px;">拖动小图标定位您的商铺位置<br/>左侧工具条可以放大缩小地图比例</span>', opts); // 创建信息窗口对象
marker.openInfoWindow(infoWindow,point); //开启信息窗口
marker.addEventListener("mouseover", function(e){
//marker.setAnimation(BMAP_ANIMATION_DROP); //停止跳动的动画
});
marker.addEventListener("dragend", function(e){
var p = marker.getPosition(); //获取marker的位置
var __p = (p.lng + "," + p.lat)
var gc = new BMap.Geocoder();
var pt = e.point;
gc.getLocation(pt, function(rs){
var addComp = rs.addressComponents;
var __address = (addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
var opts = {title : '<strong style="font-size:12px;">当前位置:</strong>'}
var infoWindow = new BMap.InfoWindow('<span style="font-size:12px;">'+__address+'(坐标:'+__p+')</span>', opts); // 创建信息窗口对象
marker.openInfoWindow(infoWindow,point); //开启信息窗口
});
});
},
1500
);
map.addControl(new BMap.NavigationControl()); //添加默认缩放平移控件
}
</script>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;}
#l-map{height:400px;width:400px;float:left;border-right:2px solid #bcbcbc;}
#r-result{height:100%;width:20%;float:left;}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.5&ak=3E9F0128D0a3fadb4e3c7c8dd111ce1c"></script>
<title>百度地图后台修改自定义坐标</title>
</head>
<body>
<div>显示坐标119.32979,26.046735</div>
<div id="l-map"></div>
</body>
</html>
<script type="text/javascript">
//api实例 http://developer.baidu.com/map/jsdemo.htm#a1_2
//文档 http://developer.baidu.com/map/reference/index.php?title=Class:%E6%A0%B8%E5%BF%83%E7%B1%BB/Map
function showPoint(){
var lng=119.32979, lat=26.046735
var map = new BMap.Map("l-map");
var point = new BMap.Point(lng,lat);
map.centerAndZoom(point,18);
setTimeout(function(){
var point = new BMap.Point(lng,lat);
var marker = new BMap.Marker(point); // 创建标注
map.addOverlay(marker); // 将标注添加到地图中
marker.enableDragging(); //可拖拽
//marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
var opts = {title : '<strong style="font-size:12px;">定位坐标:</strong>'}
var infoWindow = new BMap.InfoWindow('<span style="font-size:12px;">拖动小图标定位您的商铺位置<br/>左侧工具条可以放大缩小地图比例</span>', opts); // 创建信息窗口对象
marker.openInfoWindow(infoWindow,point); //开启信息窗口
marker.addEventListener("dragend", function(e){
var p = marker.getPosition(); //获取marker的位置
var __p = (p.lng + "," + p.lat)
var gc = new BMap.Geocoder();
var pt = e.point;
gc.getLocation(pt, function(rs){
var addComp = rs.addressComponents;
var __address = (addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
var opts = {title : '<strong style="font-size:12px;">当前位置:</strong>'}
var infoWindow = new BMap.InfoWindow('<span style="font-size:12px;">'+__address+'(坐标:'+__p+')</span>', opts); // 创建信息窗口对象
marker.openInfoWindow(infoWindow,point); //开启信息窗口
});
});
},
1500
);
map.addControl(new BMap.NavigationControl()); //添加默认缩放平移控件
}
showPoint();
</script>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;}
#l-map{height:400px;width:400px;float:left;border-right:2px solid #bcbcbc;}
#r-result{height:100%;width:20%;float:left;}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.5&ak=3E9F0128D0a3fadb4e3c7c8dd111ce1c"></script>
<title>百度地图前台显示自定义坐标</title>
</head>
<body>
<div>显示坐标119.32979,26.046735</div>
<div id="l-map"></div>
</body>
</html>
<script type="text/javascript">
//api实例 http://developer.baidu.com/map/jsdemo.htm#a1_2
//文档 http://developer.baidu.com/map/reference/index.php?title=Class:%E6%A0%B8%E5%BF%83%E7%B1%BB/Map
function showPoint(){
var lng=119.32979, lat=26.046735
var map = new BMap.Map("l-map");
var point = new BMap.Point(lng,lat);
map.centerAndZoom(point,18);
setTimeout(function(){
var point = new BMap.Point(lng,lat);
var marker = new BMap.Marker(point); // 创建标注
map.addOverlay(marker); // 将标注添加到地图中
var opts = {title : '<strong style="font-size:12px;">本店地址:</strong>'}
var infoWindow = new BMap.InfoWindow('<span style="font-size:12px;">XX区XX街XX号2楼</span>', opts); // 创建信息窗口对象
marker.openInfoWindow(infoWindow,point); //开启信息窗口
},
1500
);
map.addControl(new BMap.NavigationControl()); //添加默认缩放平移控件
}
showPoint();
</script>