2017-01-10 65 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