var map = new AMap.Map("container", { resizeEnable: true }); var placeSearch = false; var marker = false; AMap.service(["AMap.PlaceSearch"], function() { placeSearch = new AMap.PlaceSearch({ pageSize: 5, pageIndex: 1, map: map, panel: "panel" }); }); var clickEventListener = map.on('click', function(e) { var x = e.lnglat.getLng(); var y = e.lnglat.getLat(); var z = map.getZoom(); parent.setMap(x, y, z); setMaker(x, y); }); function search(txt) { if (txt.indexOf(',') != -1) { var temp = txt.split(','); txt = temp[0]; var x = temp[1]; var y = temp[2]; setMaker(x, y); } parent.closeMsg(); placeSearch.search(txt); } function setMaker(x, y) { if (marker) { marker.setPosition([x, y]); } else { marker = new AMap.Marker({ icon: "https://webapi.amap.com/theme/v1.3/markers/n/mark_r.png", position: [x, y] }); marker.setMap(map); } } function showMaker(txt) { if (txt.indexOf(',') != -1) { var temp = txt.split(','); txt = temp[0]; var x = temp[1]; var y = temp[2]; var z = temp[3]; } else { return; } map.setZoomAndCenter(z, [x, y]); new AMap.Marker({ map: map, position: [x, y] }); }