Googleマップではちょっと混乱しています。私はコーディングの初心者ではありませんが、javascriptは私のベストプラクティスではありません。Googleマップ - クリック可能なマーカーを使用したマーカークラスタリング
Googleマップマーカークラスターを使用して位置をマークします。自分のデータベースから座標を取得します。しかし、私は(クリック可能な)説明(ツールチップ)を表示したい。私は自分のコードでこれを実装する方法を知りません。
私のコードは次のようになります。
function initMap(position) {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: {lat: 51.1427552, lng: 8.2123375}
});
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
map.setCenter(pos);
}, function() {
handleLocationError(true, infoWindow, map.getCenter());
});
}
// Create an array of alphabetical characters used to label the markers.
var labels = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
// Add some markers to the map.
// Note: The code uses the JavaScript Array.prototype.map() method to
// create an array of markers based on a given "locations" array.
// The map() method here has nothing to do with the Google Maps API.
var markers = locations.map(function (location, i) {
console.log(location[2]);
return new google.maps.Marker({
position: location,
label: labels[i % labels.length],
});
});
console.log(markers);
// Add a marker clusterer to manage the markers.
var markerCluster = new MarkerClusterer(map, markers,
{imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'});
}
var locations = [{"lat":52.2885818,"lng":7.4184098,"title":"test"},{"lat":52.2756548,"lng":7.4223696,"title":"test"}]
私はあなたが、私はこれらのツールチップを統合する方法を私に表示することができます願っています。
私はこのようなコードが見つかりました:
google.maps.event.addListener(markers,'click',function() {
var infowindow = new google.maps.InfoWindow({
content:"Hello World!"
});
infowindow.open(マップ、マーカー)。 });
しかし、実装方法はわかりません。助けが夢中になるだろう。どうもありがとう!
は、あなたがこれを読んでみましたがあります。https://developers.google.com/maps/documentation/javascript/examples/event-simple –
はい、私の問題は私のループで – yfain