简单标记示例

此示例展示在地图区添加一个标记。

关键代码

    var marker = new sogou.maps.Marker({
        position: myLatlng, 
        map: map,
        title:"Hello World!"
    });	

代码解析

创建地图区。

    var myLatlng = new sogou.maps.LatLng(39.981320,116.320247);
    var myOptions = {
      zoom: 3,
      center: myLatlng,
      mapTypeId: sogou.maps.MapTypeId.ROADMAP
    }
    var map = new sogou.maps.Map(document.getElementById("map_canvas"), myOptions);

绘制标记对象。position为坐标位置。

    var marker = new sogou.maps.Marker({
        position: myLatlng, 
        map: map,
        title:"Hello World!"
    });	

完整代码

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>搜狗地图 JavaScript API示例: 简单标记示例</title>
<style type="text/css">
html {height: auto;}
body {height: auto;margin: 0;padding: 0;}
#map_canvas {width:1000px;height: 500px;position: absolute;}
@media print {#map_canvas {height: 950px;}}
</style>
<script type="text/javascript" src="//api.go2map.com/maps/js/api_v2.5.1.js"></script>
<script type="text/javascript">
  function initialize() {
    var myLatlng = new sogou.maps.LatLng(39.981320,116.320247);
    var myOptions = {
      zoom: 3,
      center: myLatlng,
      mapTypeId: sogou.maps.MapTypeId.ROADMAP
    }
    var map = new sogou.maps.Map(document.getElementById("map_canvas"), myOptions);
    
    var marker = new sogou.maps.Marker({
        position: myLatlng, 
        map: map,
        title:"Hello World!"
    });	   
  }
</script>
</head>
<body onload="initialize()">
  <div id="map_canvas"></div>
</body>
</html>

运行代码