您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

mapSection.vue 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <div>
  3. <gmap-autocomplete class="form-control mb-3 uniInput" @place_changed="setPlace">*</gmap-autocomplete>
  4. <GmapMap
  5. :center="mapCenter"
  6. :zoom="mapZoom"
  7. map-type-id="terrain"
  8. style="width: 100%; height: 500px"
  9. ref="map"
  10. >
  11. <GmapMarker v-if="this.place" :position="mapCenter" :clickable="true" :draggable="false" />
  12. </GmapMap>
  13. </div>
  14. </template>
  15. <script>
  16. /* eslint-disable */
  17. import { gmapApi } from "vue2-google-maps";
  18. export default {
  19. computed: {
  20. google: gmapApi,
  21. },
  22. data() {
  23. return {
  24. place: null,
  25. mapCenter: { lat: -26.195246, lng: 28.034088 },
  26. mapZoom: 11,
  27. streetNumber: "",
  28. streetName: "",
  29. suburb: "",
  30. city: "",
  31. province: "",
  32. country: "",
  33. postalCode: "",
  34. url: "",
  35. coords: {},
  36. };
  37. },
  38. methods: {
  39. setPlace(place) {
  40. this.place = place;
  41. this.mapCenter = place.geometry.location;
  42. this.mapZoom = 17;
  43. this.streetNumber = "";
  44. this.streetName = "";
  45. this.suburb = "";
  46. this.city = "";
  47. this.province = "";
  48. this.country = "";
  49. this.postalCode = "";
  50. this.url = "";
  51. this.coords = {};
  52. for (let i = 0; i < place.address_components.length; i++) {
  53. if (place.address_components[i].types[0] === "street_number") {
  54. this.streetNumber = place.address_components[i].long_name;
  55. }
  56. if (place.address_components[i].types[0] === "route") {
  57. this.streetName = place.address_components[i].long_name;
  58. }
  59. if (place.address_components[i].types[0] === "sublocality_level_1") {
  60. this.suburb = place.address_components[i].long_name;
  61. }
  62. if (place.address_components[i].types[0] === "locality") {
  63. this.city = place.address_components[i].long_name;
  64. }
  65. if (
  66. place.address_components[i].types[0] === "administrative_area_level_1"
  67. ) {
  68. this.province = place.address_components[i].long_name;
  69. }
  70. if (place.address_components[i].types[0] === "country") {
  71. this.country = place.address_components[i].long_name;
  72. }
  73. if (place.address_components[i].types[0] === "postal_code") {
  74. this.postalCode = place.address_components[i].long_name;
  75. }
  76. this.url = place.url;
  77. }
  78. var coords =
  79. place.geometry.viewport.Za.j + "," + place.geometry.viewport.Va.j;
  80. this.coords = coords;
  81. this.$emit("map-location", {
  82. streetNumber: this.streetNumber,
  83. streetName: this.streetName,
  84. suburb: this.suburb,
  85. city: this.city,
  86. province: this.province,
  87. country: this.country,
  88. postalCode: this.postalCode,
  89. url: this.url,
  90. coords: this.coords,
  91. });
  92. },
  93. },
  94. };
  95. </script>
  96. <style lang="scss" scoped></style>