air_set.html 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
  2. <script type="text/javascript" src="https://3gimg.qq.com/lightmap/components/geolocation/geolocation.min.js"></script>
  3. <script charset="utf-8" src="https://map.qq.com/api/js?v=2.exp"></script>
  4. <script src="https://code.jquery.com/jquery-1.8.0.min.js"></script>
  5. <iframe
  6. id="mapPage"
  7. width="100%"
  8. height="600px"
  9. frameborder=0
  10. src="https://apis.map.qq.com/tools/locpicker?search=1&type=1&key={$site.tmap_key}&referer=myapp">
  11. </iframe>
  12. <div style="text-align: right;">
  13. <button onclick="saveAddr()">保存此机场位置</button>
  14. </div>
  15. <script>
  16. var addr={}
  17. //通过iframe内嵌调用,地图选点组件的页面会根据开发者设置的iframe宽高自适应。
  18. //注:1、使用iframe调用时,为防止在大屏手机上字体过小,需在源码中加入meta信息,<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
  19. //2、开发者可以在自己的页面里通过iframe内嵌的方式调用该组件的时候,由于存在跨域的问题,需要通过html5 postMessage的方式回传用户选择的位置信息,开发者需要在自己的页面中实现一个监听函数,例如:
  20. window.addEventListener('message', function(event) {
  21. // 接收位置信息,用户选择确认位置点后选点组件会触发该事件,回传用户的位置信息
  22. var loc = event.data;
  23. if(loc && loc.module === 'locationPicker'){
  24. addr={
  25. longitude:loc.latlng.lng,
  26. latitude:loc.latlng.lat
  27. }
  28. }
  29. }, false)
  30. function saveAddr(){
  31. if(!addr.longitude){
  32. layer.alert('请选择地点')
  33. return
  34. }
  35. let a=layer.load(2,{shade:0.3})
  36. $.post('',addr,function (res) {
  37. Fast.api.close()
  38. layer.close(a)
  39. })
  40. }
  41. </script>