質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
Vue.js

Vue.jsは、Webアプリケーションのインターフェースを構築するためのオープンソースJavaScriptフレームワークです。

Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Q&A

解決済

1回答

1094閲覧

googlemap API で複数マーカーで吹き出しは一つだけ表示させたい

qooo

総合スコア9

Vue.js

Vue.jsは、Webアプリケーションのインターフェースを構築するためのオープンソースJavaScriptフレームワークです。

Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

0グッド

0クリップ

投稿2020/01/17 06:43

Vue.jsでgooglemap APIでマーカーを複数表示して、
吹き出しは1つしか表示されないようにしたいです。
(吹き出しが出てる状態で、別のマーカーをクリックすると、先に開いてる吹き出しを消してから新しい吹き出しが開くようにしたいです。)
色々自分でも試したのですが解決できず、ご教授いただきたいです。

下記のコードは、吹き出しがすべて開きっぱなしになっていて正常に動いています。
該当の箇所だけ抜粋しています。

現状のコード

<template> <div> <div :id="mapName" class="googleMap" :marker="marker"> </div> </div> </template> <script> import axios from 'axios'; export default{ components: { }, data(){ return{ mapName:'map', element: null, map: null, marker: null, latlng: null, center: {lat:35.690800, lng:139.702524}, position: null, mapOptions: null, icon1: null, icon2: null, currentMarkers: [], marker_items:[], infowindow: null, currentInfoWindow: false, } }, methods:{ success (position) { // this.center.lat = position.coords.latitude // this.center.lng = position.coords.longitude // ↑あとでコメント復活 this.element = document.getElementById(this.mapName) this.mapOptions = { zoom: 17, center: {lat:this.center.lat, lng:this.center.lng}, gestureHandling: 'greedy', scaleControl: false, mapTypeControl: false, zoomControl: false, streetViewControl: false, fullscreenControl: false, maxWidth: 178, } this.map = new google.maps.Map(this.element, this.mapOptions) this.getCurrentMarker(); setTimeout(() => { for (var i = 0; i < this.marker_items.length; i++ ){ let marker = new google.maps.Marker({ position: {lat: this.marker_items[i].latitude, lng: this.marker_items[i].longitude}, map: this.map, // icon: this.marker_items[i].icon }); this.showInfowindow(i); var contentString = `<div id="info"> ああ </div>`; let infowindow = new google.maps.InfoWindow({ content: contentString }); marker.addListener("click", function() { infowindow.open(this.map, marker); }); }; }, 1500) }, }, } </script> </style>

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

投稿2020/01/17 07:18

ku__ra__ge

総合スコア4524

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

qooo

2020/01/23 03:48

解決できました。 ありがとうございます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問