2017-06-26 6 views
-1

をクリックされたら、現在の位置はそうのGoogleマップは、 - 任意のマーカーがタイトルが言うように、私は、質問がある

、基本的な状況は、私が(データベースから)xmlファイルを使用して、いくつかポジションを埋めているということです消えます私は任意のマーカーをクリックすると、なぜ私の現在の位置マーカーが消えます。ここで

は私のコードです:

function initMap() { 


var map = new google.maps.Map(document.getElementById('map'), { 
    center: {lat: -34.397, lng: 150.644}, 
    zoom: 12 
}); 
var infoWindow = new google.maps.InfoWindow({map: map}); 



// Try HTML5 geolocation. 
if (navigator.geolocation) { 
    navigator.geolocation.getCurrentPosition(function(position) { 
    var pos = { 
     lat: position.coords.latitude, 
     lng: position.coords.longitude 
    }; 

    infoWindow.setPosition(pos); 
    infoWindow.setContent('Location found.'); 
    map.setCenter(pos); 
    }, function() { 
    handleLocationError(true, infoWindow, map.getCenter()); 
    }); 
} else { 
    // Browser doesn't support Geolocation 
    handleLocationError(false, infoWindow, map.getCenter()); 
} 

    // Change this depending on the name of your PHP or XML file 
    downloadUrl('https://www.mysite/dataMaps.php', function(data) { 
    var xml = data.responseXML; 
    var markers = xml.documentElement.getElementsByTagName('marker'); 
    Array.prototype.forEach.call(markers, function(markerElem) { 
     var name = markerElem.getAttribute('name'); 
     var address = markerElem.getAttribute('address'); 
     var type = markerElem.getAttribute('type'); 
     var point = new google.maps.LatLng(
      parseFloat(markerElem.getAttribute('lat')), 
      parseFloat(markerElem.getAttribute('lng'))); 

     var infowincontent = document.createElement('div'); 
     var strong = document.createElement('strong'); 
     strong.textContent = name 
     infowincontent.appendChild(strong); 
     infowincontent.appendChild(document.createElement('br')); 

     var text = document.createElement('text'); 
     text.textContent = address 
     infowincontent.appendChild(text); 
     var icon = customLabel[type] || {}; 
     var marker = new google.maps.Marker({ 
     map: map, 
     position: point, 
     label: icon.label 
     }); 
     marker.addListener('click', function() { 
     infoWindow.setContent(infowincontent); 
     infoWindow.open(map, marker); 
     //map.setCenter(marker.getPosition()); 

     }); 
    }); 
    }); 



} 

任意の提案?私はあなたの言うことを見

+0

あなたの "現在の位置"はインフォボックスで/で表示されますか? – geocodezip

+0

こんにちは、 '位置が見つかりました。'と私のマーカーが存在しますが、私が現在の位置(私の現在の位置s: '場所が見つかりました。')が消えます –

+0

あなたは1つの情報ウィンドウしか持っていません(マーカークリック機能によって再利用されます)。元の情報ウィンドウをそのままにしておきたい場合は、新しいマーカーを作成してマーカーに使用します(元のマーカーをクリックして機能を終了することはおそらく不可能です...) – geocodezip

答えて

0

、私はちょうど

するvar情報ウィンドウ=新しいgoogle.maps.InfoWindow({マップ:マップを})を添加し;

マーカーの内側にクリック機能があります。

marker.addListener('click', function() { 
    var infoWindow = new google.maps.InfoWindow({map: map}); 
      infoWindow.setContent(infowincontent); 
      infoWindow.open(map, marker); 

するvar情報ウィンドウ=新しいgoogle.maps.InfoWindow({マップ:マップ}

問題は、私は任意のマーカーをクリックした後、それらのいずれかの情報ウィンドウが常に存在することになりましただから私はそれらのすべてをクリックすると、それらのすべてが存在し、それらを手動で閉じる必要があります

関連する問題