获取腾讯soso地图坐标代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>获取腾讯soso地图的坐标</title> 
<script charset="utf-8" src="http://api.map.soso.com/v1.0/main.js"></script>
<script charset="utf-8" src="http://api.map.soso.com/doc/js/MarkerPicker.js"></script>
<script type="text/javascript">
function init() {
    var markers = [];
  var map = new soso.maps.Map(document.getElementById("map_container"), {
        // 地图的中心地理坐标。
          center: new soso.maps.LatLng(28.766050,104.630753)
  });
    //这里可以定义一个预设的标注比如 var point = ["39.894454","116.433952"];
    if (typeof(point) !== 'undefined') {
        map.moveTo(new soso.maps.LatLng(point[0],point[1]));
        map.zoomTo(13);
        var marker = new soso.maps.Marker({
            position: (new soso.maps.LatLng(point[0],point[1])),
            map: map
        });
        markers.push(marker);
    }
    
    var stack=[];//声明一个数组,用来保存标注位置的坐标
    var MarkerPicker=new soso.maps.MarkerPicker({
        element:document.getElementById("btn"),
        width:600,
        height:500
    });//创建MarkerPicker类的一个实例
    MarkerPicker.setIcon("http://api.map.soso.com/doc/img/pin_3.png",[0,44],[39,39]);
    //给MarkerPicker对象绑定mark事件
    soso.maps.Event.addListener(MarkerPicker,"save",function(latlng){
        stack.push(this.lat+","+this.lng);
        //document.getElementById("ditu").value=stack[0];
        map.moveTo(new soso.maps.LatLng(this.lat, this.lng));
        map.zoomTo(13);
        clearOverlays(markers);
        var marker = new soso.maps.Marker({
            position: (new soso.maps.LatLng(this.lat, this.lng)),
            map: map
        });
        markers.push(marker);
        document.getElementById("nodethemap").value=stack.join();
    });
}
//清除地图上的marker
function clearOverlays(overlays){
    var overlay;
    while(overlay = overlays.pop()){
        overlay.setMap(null);
    }
}
window.onload=init;
</script>
</head>
<body>
  <input type="text"  id="nodethemap" class="px"  style="width:200px"/>
  <span id="btn" class="btnGreen">标注位置</span> <br />
  <br />
  <div style="width:400px;height:200px;border:1px solid #ccc;" id="map_container"></div>
</form>
</body>
</html>

 

posted @ 2015-03-31 10:28  码农小兵  阅读(4582)  评论(0编辑  收藏  举报