Google Maps API ã§å ´æã¢ã¤ã³ã³ã®ãããã¢ãã (POI) ãæ¶ã
å°å³ã使ã£ã Web ãã¼ã¸ãä½ãã¨ãã«ä¾¿å©ãª Google Maps JavaScript API ã ããèªåã§ç¨æãããã¼ã«ãªã©ã®è¦ç´ ã¨ã¯å¥ã«ã主è¦ãªã¹ããããã¢ã¤ã³ã³ã¨ã©ãã«ã§ç¤ºãããã¯ãªãã¯ããã¨ãã®èª¬æãåºãããã«ãªã£ã¦ãããï¼ãã®ã¹ãããã point of interest; POI ã¨å¼ã¶ï¼
ãã åã«å°å³ãè¦ãã¨ãã«ã¯å½¹ç«ã¤ããAPI ã使ã£ã¦ä½ãä½ããã¨ããå ´åã¯éªéã«ãªããã¨ãã»ã¨ãã©ã ã
解決æ³ã¯äºã¤ããã
POI ã¢ã¤ã³ã³èªä½ãæ¶ã
ä¸ã¤ç®ã¯ POI ã®ã¢ã¤ã³ã³èªä½ãé表示ã«ããæ¹æ³ã ããã¡ãããã®å ´æãã¯ãªãã¯ãã¦ãä½ãèµ·ããªãã
次ã®ããã«ãããã¿ã¤ããå®ç¾©ãã¦è¨å®ããã
var simpleMapStyle, map; // POI ãé表示ã«ãããããã¿ã¤ããå®ç¾© simpleMapStyle = new google.maps.StyledMapType([ { featureType: "poi", elementType: "labels", stylers: [ { visibility: "off" } ] } ], { name: "Simple Map" }); map = new google.maps.Map(...); // ãããã¿ã¤ãã追å ãã¦è¨å® map.mapTypes.set("simple_map", simpleMapStyle); map.setMapTypeId("simple_map");
ãã®æ¹æ³ã¯æ£æ»æ³ã§ã¯ããããå°å³ããããã¨ãã¦å ´æãåããã«ãããªãæ¬ ç¹ãããã
POI ã®ãããã¢ããã®ã¿ç¡è¦ããæ¹æ³
ããã²ã¨ã¤ã®æ¹æ³ã¯ Stack Overflow ã¸ã®æ¸ãè¾¼ã¿ããã®ç´¹ä»ã«ãªãã
ãã®æ¹æ³ã¯ããããã¢ããã表示ãã¦ãã google.maps.InfoWindow ã®ãããã¿ã¤ããæ¸ãæãããã¨ã§ãPOI ããéããããããã¢ãããç¡è¦ããããã«ãªã£ã¦ããã
(function fixInfoWindow() { var set = google.maps.InfoWindow.prototype.set; google.maps.InfoWindow.prototype.set = function(key, val) { if (key === "map") { if (! this.get("noSuppress")) { return; } } set.apply(this, arguments); } })();
ãã ã InfoWindow ã®ãªãã·ã§ã³ã« ânoSuppressâ ãè¨å®ããã¦ããªãé常ã®ãããã¢ããã¯è¡¨ç¤ºãããªããªã£ã¦ãã¾ãã®ã§ããããã¢ãããä½ããã³ã« noSuppress = true ãè¨å®ããå¿ è¦ããããç¹ã«ä»äººã®ä½ã£ãã³ã¼ãã使ãã¨ãã¯æ³¨æãå¿ è¦ã ã
var popup = new google.maps.InfoWindow({ content: "POIã®ã°ã¼ã", noSuppress: true }); popup.setPosition(new google.maps.LatLng(36.564546, 136.6593)); popup.open(map);
ãã§ã«çæããã InfoWindow ã«å¯¾ãã¦ã¯æ¬¡ã®ããã«è¨å®ããã
popup.set("noSuppress", true);