2009-01-09 137 views
-1

我正在一個客戶,一個地方教會的網站上工作。我使用地圖頁面上的鏈接功能嵌入了Google地圖。地圖上的信息窗口包括「評論」,教會對此感到擔憂。有沒有辦法從信息窗口中刪除?我不想自己刪除任何評論,只是在信息窗口中的鏈接?自定義Google地圖信息窗口?

這可能嗎?是否有任何其他自定義選項(除了大小)可以通過查詢字符串進行操作?

回答

0

我想我找到了自己問題的答案。信息窗口本身不能修改,但通過鏈接到地圖本身而不是教堂作爲商業實體的伎倆。行車路線的鏈接仍然存在,這主要是他們想要的。

6

大約2年前,我創建了一個custom map,它完全控制了氣泡的內容,使用API​​和一些代碼操作。點擊上面的鏈接進行演示。我已經清理了此答案的代碼,但要實現,您需要將所有YOUR__BLANK__HERE文本替換爲適當的值。

步驟1:調用API gMaps

<script src="http://maps.google.com/maps?file=api&v=2&key=YOUR_API_KEY_HERE" 
     type="text/javascript"> 
</script> 

第2步:在文檔的正文中,創建一個ID元素 「地圖」。使用CSS大小和位置。它需要高度和寬度。

<div id="map" class="content"></div> 

步驟3:股利後已在DOM被定義,它是安全的插入下面的腳本標籤:

<script type="text/javascript"> 
//<![CDATA[ 

// Check to see if this browser can run the Google API 
if (GBrowserIsCompatible()) { 

    var gmarkers = []; 
    var htmls = []; 
    var to_htmls = []; 
    var from_htmls = []; 
    var i=0; 

    // A function to create the marker and set up the event window 
    function createMarker(point,name,html) { 
    var marker = new GMarker(point); 

    // The info window version with the "to here" form open 
    to_htmls[i] = html + 
     '<br />Start address:<form action="http://maps.google.com/maps" method="get">' + 
     '<input type="text" SIZE=40 MAXLENGTH=40 name="saddr" id="saddr" value="" /><br>' + 
     '<INPUT value="Get Directions" TYPE="SUBMIT">' + 
     '<input type="hidden" name="daddr" value="' + point.lat() + ',' + point.lng() + 
       // "(" + name + ")" + 
     '"/>'; 
    // The inactive version of the direction info 
    html = html + '<br><a href="javascript:tohere('+i+')">Get Directions<'+'/a>'; 

    GEvent.addListener(marker, "click", function() { 
     marker.openInfoWindowHtml(html); 
    }); 
    gmarkers[i] = marker; 
    htmls[i] = html; 
    i++; 
    return marker; 
    } 

    // functions that open the directions forms 
    function tohere(i) { 
    gmarkers[i].openInfoWindowHtml(to_htmls[i]); 
    } 

    // Display the map, with some controls and set the initial location 
    var map = new GMap2(document.getElementById("map")); 
    map.setCenter(new GLatLng(
    YOUR_LATITUDE_HERE, 
    YOUR_LONGITUDE_HERE 
    ), 
    YOUR_ZOOM_LEVEL_HERE // a value of 13 worked for me 
); 

    // Set up one marker with an info window 
    var marker = createMarker(
    new GLatLng(
     YOUR_LATITUDE_HERE, 
     YOUR_LONGITUDE_HERE 
    ), 
    'YOUR_MARKER_NAME_HERE', 
    '<i>YOUR_HTML_HERE<'+'/i>'); 

    /* repeat the process to add more markers 
    map.addOverlay(marker); 
    var marker = createMarker(
    new GLatLng(
     YOUR_LATITUDE_HERE, 
     YOUR_LONGITUDE_HERE 
    ), 
    'YOUR_MARKER_NAME_HERE', 
    '<i>YOUR_HTML_HERE<'+'/i>'); 
    map.addOverlay(marker);*/ 
} 


// display a warning if the browser was not compatible 
else { 
    alert("Sorry, the Google Maps API is not compatible with this browser"); 
} 

// This Javascript is based on code provided by the 
// Blackpool Community Church Javascript Team 
// http://www.commchurch.freeserve.co.uk/ 
// http://www.econym.demon.co.uk/googlemaps/ 

//]]> 
</script> 

使用此代碼,泡沫包含您指定的HTML在YOUR_HTML_HERE加上獲取路線的鏈接,該路線(點擊時)變成了要求出發地址的文本框。不幸的是,查詢的結果會在一個新的瀏覽器窗口中打開(因爲在原始發佈時,API不包括路線功能)

+0

您可以在某處連接您的鏈接嗎?這個去了404. – 2015-10-21 10:07:22

相關問題