Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

addressAutoComplete.vue 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <div>
  3. <gmap-autocomplete class="form-control mb-3 uniInput" @place_changed="setPlace"></gmap-autocomplete>
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. name: "AddressAutoComplete",
  9. props: {
  10. placeholder: {
  11. default: "ENTER LOCATION",
  12. },
  13. },
  14. data() {
  15. return {
  16. streetNumber: "",
  17. streetName: "",
  18. suburb: "",
  19. city: "",
  20. province: "",
  21. country: "",
  22. postalCode: "",
  23. url: "",
  24. coords: {},
  25. };
  26. },
  27. methods: {
  28. setPlace(place) {
  29. this.streetNumber = "";
  30. this.streetName = "";
  31. this.suburb = "";
  32. this.city = "";
  33. this.province = "";
  34. this.country = "";
  35. this.postalCode = "";
  36. this.url = "";
  37. this.coords = {};
  38. for (let i = 0; i < place.address_components.length; i++) {
  39. if (place.address_components[i].types[0] === "street_number") {
  40. this.streetNumber = place.address_components[i].long_name;
  41. }
  42. if (place.address_components[i].types[0] === "route") {
  43. this.streetName = place.address_components[i].long_name;
  44. }
  45. if (place.address_components[i].types[0] === "sublocality_level_1") {
  46. this.suburb = place.address_components[i].long_name;
  47. }
  48. if (place.address_components[i].types[0] === "locality") {
  49. this.city = place.address_components[i].long_name;
  50. }
  51. if (
  52. place.address_components[i].types[0] === "administrative_area_level_1"
  53. ) {
  54. this.province = place.address_components[i].long_name;
  55. }
  56. if (place.address_components[i].types[0] === "country") {
  57. this.country = place.address_components[i].long_name;
  58. }
  59. if (place.address_components[i].types[0] === "postal_code") {
  60. this.postalCode = place.address_components[i].long_name;
  61. }
  62. }
  63. this.url = place.url;
  64. this.coords = place.geometry.location;
  65. this.$emit("GoogleAddress", {
  66. streetNumber: this.streetNumber,
  67. streetName: this.streetName,
  68. suburb: this.suburb,
  69. city: this.city,
  70. province: this.province,
  71. country: this.country,
  72. postalCode: this.postalCode,
  73. url: this.url,
  74. coords: this.coords,
  75. });
  76. },
  77. },
  78. };
  79. </script>