<!doctype html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width"> <title>地图点击事件</title> <script src="/assets/js/jquery.min.js"></script> <link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/> <script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=您申请的key值"></script> <script type="text/javascript" src="http://cache.amap.com/lbs/static/addToolbar.js"></script> </head> <body> <div id="container"></div> <script type="text/javascript"> //初始化地图对象,加载地图 var map = new AMap.Map("container", { resizeEnable: true, center: [121.50457499999999, 31.242533333333334], zoom: 17 }); map.on('click', function(e) { $.get("/index.php?x="+e.lnglat.getLng()+"&y="+e.lnglat.getLat()+"&a=savelocation",function () { alert('您在[ '+e.lnglat.getLng()+','+e.lnglat.getLat()+' ]的位置点击了地图!'); }); }); </script> </body> </html>
<!doctype html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width"> <title>轨迹回放</title> <link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/> <script src="http://webapi.amap.com/maps?v=1.3&key=6d116d4252d7f7ce90a808ace0812248"></script> <script type="text/javascript" src="http://cache.amap.com/lbs/static/addToolbar.js"></script> </head> <body> <div id="container"></div> <div class="button-group"> <input type="button" class="button" value="开始动画" id="start"/> <input type="button" class="button" value="停止动画" id="stop"/> </div> <script> var marker, lineArr = []; var map = new AMap.Map("container", { resizeEnable: true, center: [116.397428, 39.90923], zoom: 17 }); map.on("complete", completeEventHandler); AMap.event.addDomListener(document.getElementById('start'), 'click', function() { marker.moveAlong(lineArr, 500); }, false); AMap.event.addDomListener(document.getElementById('stop'), 'click', function() { marker.stopMove(); }, false); // 地图图块加载完毕后执行函数 function completeEventHandler() { marker = new AMap.Marker({ map: map, position: [121.50457499999999, 31.242533333333334], icon: "http://webapi.amap.com/images/car.png", offset: new AMap.Pixel(-26, -13), autoRotation: true }); //var lngX = 121.50457499999999, latY = 31.242533333333334; lineArr.push([121.511817, 31.243308]);lineArr.push([121.51054, 31.242932]);lineArr.push([121.502258, 31.243474]);lineArr.push([121.506131, 31.242831]);lineArr.push([121.509939, 31.243574]);lineArr.push([121.504328, 31.244758]);lineArr.push([121.500219, 31.244694]);lineArr.push([121.502376, 31.240657]);lineArr.push([121.51127, 31.243538]);lineArr.push([121.510615, 31.240281]);lineArr.push([121.506184, 31.239584]);lineArr.push([121.51005332464929, 31.236946810744094]);lineArr.push([121.50769666666665, 31.243458333333333]); // 绘制轨迹 var polyline = new AMap.Polyline({ map: map, path: lineArr, strokeColor: "#00A", //线颜色 strokeOpacity: 1, //线透明度 strokeWeight: 3, //线宽 strokeStyle: "solid" //线样式 }); map.setFitView(); } </script> </body> </html>