码迷,mamicode.com
首页 > 其他好文 > 详细

高德地图片添加标记

时间:2017-08-24 17:09:19      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:height   bounds   fun   body   rip   let   city   map   org   

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <script type="text/javascript" src="jquery.v1.10.2.js"></script>
    <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.3&key=******"></script>
</head>
    <body>
        <div id="allmap"></div>
        <script type="text/javascript">
            var marker,map = new AMap.Map("allmap", {
                resizeEnable: true
            });

            $(function () {
                $("#allmap").css("height", $(window.parent.document).height() - 123 + "px");

                map.plugin(["AMap.CitySearch"], function () {
                    //实例化城市查询类
                    var citysearch = new AMap.CitySearch();

                    //自动获取用户IP,返回当前城市
                    citysearch.getLocalCity(function (status, result) {
                        if (status === complete && result.info === OK) {
                            if (result && result.city && result.bounds) {
                                var city = result.city;
                                //var citybounds = result.bounds;
                                //alert(city);
                                console.info(city);
                                //myFun(cityinfo);
                                map.setBounds(result.bounds);
                            }
                        }
                    });
                });

                var position = [];


                map.on(click, function (e) {

                    if (marker) {
                        marker.setMap(null);
                        marker = null;
                    }

                    marker = new AMap.Marker({
                        icon: "http://webapi.amap.com/theme/v1.3/markers/n/mark_b.png",
                        position: [e.lnglat.getLng(), e.lnglat.getLat()]
                    });
                    marker.setMap(map);

                    console.info(position);
                    console.info(e.lnglat.getLng());
                    console.info(e.lnglat.getLat());

                });
            });
        </script>
    </body>
</html>

 

高德地图片添加标记

标签:height   bounds   fun   body   rip   let   city   map   org   

原文地址:http://www.cnblogs.com/gouzhiguo/p/7423927.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!