いつもお世話になっております。
Google Maps API にて外部のJSONファイルを読み込みピンを表示させることに成功しました。
が、非表示としたいピンが何本かあり、JSONを読み込む箇所で特定の配列を保持しているピンのみを抽出したいと考えておりますがそのようなことはできますでしょうか。
現在は下記のようなJSになっています。
var map; var markers = []; var infowindow = new google.maps.InfoWindow(); function initialize() { geocoder = new google.maps.Geocoder(); var center = new google.maps.LatLng(XXX,XXX); map = new google.maps.Map(document.getElementById('map'), { zoom: 12, center: center, mapTypeId: google.maps.MapTypeId.ROADMAP }); markMultiple(); } function markMultiple(){ $.getJSON('JSONファイル', function(data) { $.each(data, function(i,obj) { var latLng = new google.maps.LatLng( obj.map_latitude, obj.map_longitude ); var content = ピンをクリック後吹き出しの内容; markMap(latLng, content); }); var markerCluster = new MarkerClusterer(map, markers); }); } function markMap(position, content){ var marker = new google.maps.Marker({ position: position, icon: 'img/icon.png' }); google.maps.event.addListener(marker, 'click', function() { infowindow.setContent(content); infowindow.open(map, marker); }); markers.push(marker); } google.maps.event.addDomListener(window, 'load', initialize);
JSONは以下のようになっています。
以下でいえば"timer": "on"でdateが入力されているとなっている原宿のピンを表示させたいです。
[ { "id": "0", "station": "渋谷駅", "timer": "", "date": "2004-12-22T15:00:00.000Z", "map_latitude": XXX, "map_longitude": XXX, }, { "id": "1", "station": "原宿駅", "timer": "on", "date": "2004-12-23T15:00:00.000Z", "map_latitude": XXX, "map_longitude": XXX, }, { "id": "2", "station": "新宿駅", "timer": "on", "date": "", "map_latitude": XXX, "map_longitude": XXX, } ]
お力添えをいただけますと幸いです。
どうぞよろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/17 06:02