vue 获取坐标 及 调用腾讯地图

水深无声 2022-09-12 01:43 443阅读 0赞
  1. addrHand() {
  2. let that = this
  3. console.log(that.jobsUserId)
  4. $.ajax({
  5. type: "get",
  6. dataType: 'jsonp',
  7. data: {
  8. key: "youkey", // 填申请到的腾讯key
  9. address:that.address, //具体的地址
  10. output: 'jsonp' //返回格式:支持JSON/JSONP,默认JSON
  11. },
  12. jsonp: "callback",
  13. jsonpCallback: "QQmap",
  14. url: "https://apis.map.qq.com/ws/geocoder/v1/?",
  15. success: function(json) {
  16. console.log(that.address)
  17. if (json.status == 0) {
  18. that.latitude = json.result.location.lat
  19. that.longitude = json.result.location.lng
  20. that.map(that.latitude,that.longitude)
  21. that.$message({
  22. message: '成功获取位置的经纬度',
  23. type: 'success'
  24. })
  25. } else {
  26. that.$message.error('获取该位置经纬度失败')
  27. }
  28. },
  29. error: function(err) {
  30. that.$message.error('异常错误,请刷新浏览器后重试')
  31. }
  32. })
  33. },
  34. map(latitude,longitude) {
  35. var center = new TMap.LatLng(latitude, longitude);//设置中心点坐标
  36. //初始化地图
  37. var map = new TMap.Map(container, {
  38. center: center
  39. });
  40. //初始化marker
  41. var marker = new TMap.MultiMarker({
  42. id: "marker-layer", //图层id
  43. map: map,
  44. styles: { //点标注的相关样式
  45. "marker": new TMap.MarkerStyle({
  46. "width":50,
  47. "height":50,
  48. "anchor": { x: 16, y: 32 },
  49. "src": "../../static/img/marker.png"
  50. })
  51. },
  52. geometries: [{ //点标注数据数组
  53. "id": "demo",
  54. "styleId": "marker",
  55. "position": new TMap.LatLng(latitude, longitude),
  56. "properties": {
  57. "title": "marker"
  58. }
  59. }]
  60. });
  61. },
  62. index.html
  63. <script charset="utf-8" src="https://map.qq.com/api/gljs?v=1.exp&key=youkey"></script>

发表评论

表情:
评论列表 (有 0 条评论,443人围观)

还没有评论,来说两句吧...

相关阅读

    相关 vue2.0引入地图

    百度很多东西,然后我没找到腾讯地图在VUE2.0里面的引用。于是根据找的其他地图引用资料进行尝试。步骤如下。 首先在src里面建立了TMap.js的文件,内容如下: