2017-01-10 62 views
0

我爲Google地圖位置編寫了一些HTML。不同地址的谷歌地圖位置onclick

在頁面中,我創建了兩個不同的按鈕地址作爲View on map,所以當我點擊按鈕時,它會重定向到另一個頁面,它應該只使用地址獲取Google地圖位置。

但是,在結果頁面上,它向我顯示只有一個地址的Google地圖位置。該腳本正在那裏使用任何地址,但我需要它與onClick事件一起工作。

這裏是鏈接:

(此頁鏈接將顯示您自己的按鈕,兩個地址)

http://happy1.studioscue.in/hello.html

...和其他鏈接會顯示結果Google位置應顯示的頁面。澳大利亞只有一個谷歌地圖,那是因爲我在那裏使用澳大利亞身體標籤&這個頁面。這個鏈接是:在評論中提到

http://happy1.studioscue.in/google.html

+0

你從來沒有通過任何地圖參數或座標來google.html您 –

+0

那麼,如何解決這個問題請告訴我 – neha

+0

的鏈接是死在了這個問題,對於依靠任何問題的危險在外部鏈接上。這確實意味着它需要關閉。請嘗試儘可能保持您的問題獨立,以限制所需的關閉和刪除數量。 – halfer

回答

1

正如上面@Devs,你必須通過一些貼圖參數(地名或座標),以google.html您頁。我修改了招呼頁面:

<!doctype html> 
<html> 
    <head> 
     <meta charset="utf-8"> 
     <title>Untitled Document</title> 
    </head> 

    <body> 
     <address> 
      Sector 75-Noid... 
     </address> 
     <a href="google.html?q=France"><button type="button">view on map</button></a> 

     <address>Delhi</address> 
     <a href="google.html?q=Delhi"><button type="button">view on map</button></a> 
    </body> 
</html> 

正如你所看到的,google.html您的聯繫現在有「Q」的查詢字符串參數,這將在google.html您頁面中使用:

<!DOCTYPE html> 
<html> 
    <head> 
     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> 
     <script src="http://jashkenas.github.com/coffee-script/extras/coffee-script.js"></script> 
     <meta charset=utf-8 /> 
     <title>Welcome to JS Bin</title> 
     <meta name="viewport" content="width=device-width"> 
     <link href='http://fonts.googleapis.com/css?family=Doppio+One' rel='stylesheet' type='text/css'> 
     <script type="text/javascript"> 
      $(document).ready(function() { 
       $("address").each(function() {       
        var embed ="<iframe width='425' height='350' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='https://maps.google.com/maps?&amp;q="+ encodeURIComponent(getParameterByName('q')) +"&amp;output=embed'></iframe>"; 
        $(this).html(embed);  
       }); 

       function getParameterByName(name, url) { 
        if (!url) { 
         url = window.location.href; 
        } 
        name = name.replace(/[\[\]]/g, "\\$&"); 
        var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), 
        results = regex.exec(url); 
        if (!results) return null; 
        if (!results[2]) return ''; 
        return decodeURIComponent(results[2].replace(/\+/g, " ")); 
       } 
      }); 
     </script> 
    </head> 
    <body> 
     <address>Australia</address> 
    </body> 
</html> 

你可以嘗試在工作演示here

+0

你好,我檢查了你的演示,但在第一個地址是扇區75-noida,但點擊它顯示法國地圖位置和我看到代碼中你寫的代碼爲2個地址,但會有很多地址,所以所有他們將不得不手動將代碼寫入ancher標籤中? &它是否會與動態地址工作,請儘快回覆我謝謝和問候 – neha